QQmlEngine: Fix documentation

The documentation should not recommend passing data via the context.
Rather, it should at least mention what a QQmlEngine actually is.

Pick-to: 6.6 6.5
Change-Id: Iee4faba7bb4e3bbbe385474badcb9781688f7147
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
This commit is contained in:
Ulf Hermann 2023-10-19 10:04:50 +02:00
parent 0642ea5890
commit 495cf09a03
1 changed files with 8 additions and 21 deletions

View File

@ -580,29 +580,16 @@ void QQmlEnginePrivate::init()
\inmodule QtQml
\brief The QQmlEngine class provides an environment for instantiating QML components.
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.
A QQmlEngine is used to manage \l{components}{QQmlComponent} and objects created from
them and execute their bindings and functions. QQmlEngine also inherits from
\l{QJSEngine} which allows seamless integration between your QML components and
JavaScript code.
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.
Each QML component is instantiated in a QQmlContext. In QML, contexts are arranged
hierarchically and this hierarchy is managed by the QQmlEngine. By default,
components are instantiated in the \l {QQmlEngine::rootContext()}{root context}.
\code
QQmlEngine engine;
QQmlComponent component(&engine);
component.setData("import QtQuick 2.0\nText { text: \"Hello world!\" }", QUrl());
QQuickItem *item = qobject_cast<QQuickItem *>(component.create());
//add item to view, etc
...
\endcode
In this case, the Text item will be created in the engine's
\l {QQmlEngine::rootContext()}{root context}.
\sa QQmlComponent, QQmlContext, {QML Global Object}
\sa QQmlComponent, QQmlContext, {QML Global Object}, QQmlApplicationEngine
*/
/*!