QQmlApplicationEngine Class
The QQmlApplicationEngine class loads the main QML document of an application. More…
| Header | #include <QQmlApplicationEngine> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Qml) |
| Module | Nt Qml C++ Classes |
| Inherits | QQmlEngine |
List of all members, including inherited members
Public Functions
| QQmlApplicationEngine(QObject *parent = nullptr) | |
| QQmlApplicationEngine(const QUrl &url, QObject *parent = nullptr) | |
| QQmlApplicationEngine(const QString &filePath, QObject *parent = nullptr) | |
| QQmlApplicationEngine(const QString &uri, const QString &typeName, QObject *parent = nullptr) | |
| ~QQmlApplicationEngine() | |
| QList<QObject *> | rootObjects() const |
| void | setInitialProperties(const QVariantMap &initialProperties) |
Public Slots
| void | load(const QUrl &url) |
| void | load(const QString &filePath) |
| void | loadFromModule(const QString &uri, const QString &typeName) |
| void | setExtraFileSelectors(const QStringList &extraFileSelectors) |
| void | loadData(const QByteArray &data, const QUrl &url = QUrl()) |
Signals
| void | objectCreated(QObject *object, const QUrl &url) |
| void | objectCreationFailed(const QUrl &url) |
Detailed Description
The engine loads a document, makes its root object, and keeps it until the engine is destroyed:
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("greeting", QStringLiteral("hello"));
engine.load(QString::fromLocal8Bit(argv[1]));
if (engine.rootObjects().isEmpty())
return 1;
return app.exec();
Qt.quit() and Qt.exit() in documents quit the application.
See also QQmlEngine and QQmlComponent.
Differences from Qt
There are no file selectors (setExtraFileSelectors() keeps them), no translations and no network URLs.
Member Function Documentation
QQmlApplicationEngine::QQmlApplicationEngine(QObject *parent = nullptr)
Constructs an engine with the given parent.
QQmlApplicationEngine::QQmlApplicationEngine(const QUrl &url, QObject *parent = nullptr)
Constructs an engine with the given parent and loads the document at url.
QQmlApplicationEngine::QQmlApplicationEngine(const QString &filePath, QObject *parent = nullptr)
Constructs an engine with the given parent and loads the file filePath.
QQmlApplicationEngine::QQmlApplicationEngine(const QString &uri, const QString &typeName, QObject *parent = nullptr)
Constructs an engine with the given parent and loads the type typeName of the module uri.
QQmlApplicationEngine::~QQmlApplicationEngine()
Destroys the engine and the root objects it made.
void QQmlApplicationEngine::load(const QUrl &url)
Loads the document at url and makes its root object.
void QQmlApplicationEngine::load(const QString &filePath)
This is an overloaded function.
Loads the file filePath; a path starting with :/ is a resource.
void QQmlApplicationEngine::loadData(const QByteArray &data, const QUrl &url = QUrl())
Reads the document data, whose relative URLs are resolved against url, and makes its root object.
void QQmlApplicationEngine::loadFromModule(const QString &uri, const QString &typeName)
Loads the type typeName of the module uri and makes an object of it.
void QQmlApplicationEngine::objectCreated(QObject *object, const QUrl &url)
This signal is emitted when the root object object of url has been created, or with a null object if it could not be.
void QQmlApplicationEngine::objectCreationFailed(const QUrl &url)
This signal is emitted when the root object of url could not be created.
QList<QObject *> QQmlApplicationEngine::rootObjects() const
Returns the root objects of the documents loaded.
void QQmlApplicationEngine::setExtraFileSelectors(const QStringList &extraFileSelectors)
Keeps extraFileSelectors; Nt has no file selectors.
void QQmlApplicationEngine::setInitialProperties(const QVariantMap &initialProperties)
Sets the properties that the root objects of documents loaded later get to initialProperties.