QQmlApplicationEngine Class

QQmlApplicationEngine provides a convenient way to load an application from a single QML file. More...

Header: #include <QQmlApplicationEngine>
qmake: QT += qml
Since: Qt 5.1
Inherits: QQmlEngine

This class was introduced in Qt 5.1.

Detailed Description

This class combines a QQmlEngine and QQmlComponent to provide a convenient way to load a single QML file. It also exposes some central application functionality to QML, which a C++/QML hybrid application would normally control from C++.

It can be used like so:

 #include <QGuiApplication>
 #include <QQmlApplicationEngine>

 int main(int argc, char *argv[])
 {
     QGuiApplication app(argc, argv);
     QQmlApplicationEngine engine("main.qml");
     return app.exec();
 }

Unlike QQuickView, QQmlApplicationEngine does not automatically create a root window. If you are using visual items from Qt Quick, you will need to place them inside of a Window.

You can also use QCoreApplication with QQmlApplicationEngine, if you are not using any QML modules which require a QGuiApplication (such as QtQuick).

List of configuration changes from a default QQmlEngine:

  • Connecting Qt.quit() to QCoreApplication::quit()
  • Automatically loads translation files from an i18n directory adjacent to the main QML file.
    • Translation files must have "qml_" prefix e.g. qml_ja_JP.qm.
  • Translations are reloaded when the QJSEngine::uiLanguage / Qt.uiLanguage property is changed.
  • Automatically sets an incubation controller if the scene contains a QQuickWindow.
  • Automatically sets a QQmlFileSelector as the url interceptor, applying file selectors to all QML files and assets.

The engine behavior can be further tweaked by using the inherited methods from QQmlEngine.