QQmlApplicationEngine¶
QQmlApplicationEngineprovides a convenient way to load an application from a single QML file. More…

Synopsis¶
Functions¶
def
rootObjects()
Slots¶
def
load(filePath)def
load(url)def
loadData(data[, url=QUrl()])def
setInitialProperties(initialProperties)
Signals¶
def
objectCreated(object, url)
Detailed Description¶
This class combines a
QQmlEngineandQQmlComponentto 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,QQmlApplicationEnginedoes 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
QCoreApplicationwithQQmlApplicationEngine, if you are not using any QML modules which require aQGuiApplication(such asQtQuick).List of configuration changes from a default
QQmlEngine:
Translations are reloaded when the
QJSEngine::uiLanguage/Qt.uiLanguageproperty is changed.Automatically sets an incubation controller if the scene contains a
QQuickWindow.Automatically sets a
QQmlFileSelectoras 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.
- class PySide2.QtQml.QQmlApplicationEngine([parent=None])¶
PySide2.QtQml.QQmlApplicationEngine(filePath[, parent=None])
PySide2.QtQml.QQmlApplicationEngine(url[, parent=None])
- param parent:
- param url:
- param filePath:
str
Create a new
QQmlApplicationEnginewith the givenparent. You will have to callload()later in order to load a QML file.
- PySide2.QtQml.QQmlApplicationEngine.load(filePath)¶
- Parameters:
filePath – str
- PySide2.QtQml.QQmlApplicationEngine.load(url)
- Parameters:
url –
PySide2.QtCore.QUrl
- PySide2.QtQml.QQmlApplicationEngine.loadData(data[, url=QUrl()])¶
- Parameters:
data –
PySide2.QtCore.QByteArrayurl –
PySide2.QtCore.QUrl
Loads the QML given in
data. The object tree defined bydatais instantiated immediately.If a
urlis specified it is used as the base url of the component. This affects relative paths within the data and error messages.If an error occurs, error messages are printed with
qWarning.
- PySide2.QtQml.QQmlApplicationEngine.objectCreated(object, url)¶
- Parameters:
object –
PySide2.QtCore.QObjecturl –
PySide2.QtCore.QUrl
- PySide2.QtQml.QQmlApplicationEngine.rootObjects()¶
- Return type:
Returns a list of all the root objects instantiated by the
QQmlApplicationEngine. This will only contain objects loaded viaload()or a convenience constructor.Note
In Qt versions prior to 5.9, this function is marked as non-
const.
- PySide2.QtQml.QQmlApplicationEngine.setInitialProperties(initialProperties)¶
- Parameters:
initialProperties –
Sets the
initialPropertieswith which the QML component gets initialized after it gets loaded.QQmlApplicationEngine engine; EventDatabase eventDatabase; EventMonitor eventMonitor; engine.setInitialProperties({ { "eventDatabase", QVariant::fromValue(&eventDatabase) }, { "eventMonitor", QVariant::fromValue(&eventMonitor) } });
See also
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.