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

Detailed Description¶
This class combines a
QQmlEngine
andQQmlComponent
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
withQQmlApplicationEngine
, if you are not using any QML modules which require aQGuiApplication
(such asQtQuick
).List of configuration changes from a default
QQmlEngine
:
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
.
-
class
QQmlApplicationEngine
([parent=None])¶ QQmlApplicationEngine(filePath[, parent=None])
QQmlApplicationEngine(url[, parent=None])
- param parent
QObject
- param url
QUrl
- param filePath
unicode
Create a new
QQmlApplicationEngine
with the givenparent
. You will have to callload()
later in order to load a QML file.Create a new
QQmlApplicationEngine
and loads the QML file at the givenfilePath
, which must be a local file path. If a relative path is given then it will be interpreted as relative to the working directory of the application.This is provided as a convenience, and is the same as using the empty constructor and calling load afterwards.
Create a new
QQmlApplicationEngine
and loads the QML file at the givenurl
. This is provided as a convenience, and is the same as using the empty constructor and calling load afterwards.
-
PySide2.QtQml.QQmlApplicationEngine.
load
(url)¶ - Parameters
url –
QUrl
Loads the root QML file located at
url
. The object tree defined by the file is created immediately for local file urls. Remote urls are loaded asynchronously, listen to theobjectCreated
signal to determine when the object tree is ready.If an error occurs, the
objectCreated
signal is emitted with a null pointer as parameter and error messages are printed withqWarning
.
-
PySide2.QtQml.QQmlApplicationEngine.
load
(filePath) - Parameters
filePath – unicode
Loads the root QML file located at
filePath
.filePath
must be a path to a local file. IffilePath
is a relative path, it is taken as relative to the application’s working directory. The object tree defined by the file is instantiated immediately.If an error occurs, error messages are printed with
qWarning
.
-
PySide2.QtQml.QQmlApplicationEngine.
loadData
(data[, url=QUrl()])¶ - Parameters
data –
QByteArray
url –
QUrl
Loads the QML given in
data
. The object tree defined bydata
is instantiated immediately.If a
url
is 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 –
QObject
url –
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
.