From ed6f55ca126c80514e886b3b400a22ba5d443589 Mon Sep 17 00:00:00 2001 From: Topi Reinio Date: Mon, 7 Dec 2020 16:56:05 +0100 Subject: 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 --- src/qml/qml/qqmlengine.cpp | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) (limited to 'src/qml/qml/qqmlengine.cpp') 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::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(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. -- cgit v1.2.3