QQmlEngine Class▲
-
Header: QQmlEngine
-
Since: Qt 5.0
-
CMake:
find_package(Qt6 REQUIRED COMPONENTS Qml)
target_link_libraries(mytarget PRIVATE Qt6::Qml)
-
qmake: QT += qml
-
Inherits: QJSEngine
-
Inherited By: QQmlApplicationEngine
Detailed Description▲
Each QML component is instantiated in a QQmlContext. QQmlContext's are essential for passing data to QML components. In QML, contexts are arranged hierarchically and this hierarchy is managed by the QQmlEngine.
Prior to creating any QML components, an application must have created a QQmlEngine to gain access to a QML context. The following example shows how to create a simple Text item.
QQmlEngine engine;
QQmlComponent component(&
amp;engine);
component.setData("import QtQuick 2.0
\n
Text { text:
\"
Hello world!
\"
}"
, QUrl());
QQuickItem *
item =
qobject_cast&
lt;QQuickItem *&
gt;(component.create());
//add item to view, etc
...
In this case, the Text item will be created in the engine's root context.
See Also▲
See also QQmlComponent, QQmlContext, QML Global Object