diff options
author | Topi Reinio <topi.reinio@qt.io> | 2020-12-07 16:56:05 +0100 |
---|---|---|
committer | Topi Reinio <topi.reinio@qt.io> | 2020-12-08 11:35:06 +0100 |
commit | ed6f55ca126c80514e886b3b400a22ba5d443589 (patch) | |
tree | 22c2b46f4fa33ed2be61435280ca85779aaa931a /src/qml/qml/qqmlengine.cpp | |
parent | c3860cd04bbc089ef95bc441a1f8f1e46f9606f8 (diff) |
Doc: Fix occurrences of \Q_OBJECT in code snippets
'Q_OBJECT', even in a comment, interferes with automoc.
Prefixing it with a backslash solves the automoc issue,
but documentation looks wrong as content inside \code
is taken verbatim.
Move code snippets to doc/snippets and refer to them
with \snippet commands.
Pick-to: 6.0
Change-Id: Ied7fdf87ef5edd2b237498b91b162c19bf7bc636
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlengine.cpp')
-rw-r--r-- | src/qml/qml/qqmlengine.cpp | 32 |
1 files changed, 8 insertions, 24 deletions
diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index 0b6b456473..0208b99621 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -1368,34 +1368,18 @@ void QQmlEngine::captureProperty(QObject *object, const QMetaProperty &property) type, either a default constructed QJSValue or a \c nullptr is returned. QObject* example: - \code - class MySingleton : public QObject { - \Q_OBJECT - - // Register as default constructed singleton. - QML_ELEMENT - QML_SINGLETON - - static int typeId; - // ... - }; - MySingleton::typeId = qmlTypeId(...); - - // Retrieve as QObject* - QQmlEngine engine; - MySingleton* instance = engine.singletonInstance<MySingleton*>(MySingleton::typeId); - \endcode + \snippet code/src_qml_qqmlengine.cpp 0 + \codeline + \snippet code/src_qml_qqmlengine.cpp 1 + \codeline + \snippet code/src_qml_qqmlengine.cpp 2 QJSValue example: - \code - // Register with QJSValue callback - int typeId = qmlRegisterSingletonType(...); - // Retrieve as QJSValue - QQmlEngine engine; - QJSValue instance = engine.singletonInstance<QJSValue>(typeId); - \endcode + \snippet code/src_qml_qqmlengine.cpp 3 + \codeline + \snippet code/src_qml_qqmlengine.cpp 4 It is recommended to store the QML type id, e.g. as a static member in the singleton class. The lookup via qmlTypeId() is costly. |