From ba8051b7e716c34db96db6c68f03ef928760e1fb 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. Change-Id: Ied7fdf87ef5edd2b237498b91b162c19bf7bc636 Reviewed-by: Paul Wicking (cherry picked from commit ed6f55ca126c80514e886b3b400a22ba5d443589) Reviewed-by: Qt Cherry-pick Bot --- src/qml/qml/qqmlengine.cpp | 32 ++++++++------------------------ src/qml/qml/qqmllist.cpp | 39 +++------------------------------------ src/qml/qml/qqmlparserstatus.cpp | 14 +------------- 3 files changed, 12 insertions(+), 73 deletions(-) (limited to 'src/qml/qml') 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. diff --git a/src/qml/qml/qqmllist.cpp b/src/qml/qml/qqmllist.cpp index 51499f816d..a3380a6c22 100644 --- a/src/qml/qml/qqmllist.cpp +++ b/src/qml/qml/qqmllist.cpp @@ -436,18 +436,7 @@ QML list properties are type-safe - in this case \c {Fruit} is a QObject type th When assigning the property in a derived type, the values are appended to those of the base class. This is the default behavior. - \code - class FruitBasket : QObject { - \Q_OBJECT - QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_APPEND - Q_PROPERTY(QQmlListProperty fruit READ fruit) - - public: - // ... - QQmlListProperty fruit(); - // ... - }; - \endcode + \snippet code/src_qml_qqmllist.cpp 0 \sa QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_REPLACE_IF_NOT_DEFAULT \sa QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_REPLACE @@ -463,18 +452,7 @@ QML list properties are type-safe - in this case \c {Fruit} is a QObject type th the base class unless it's the default property. In the case of the default property, values are appended to those of the base class. - \code - class FruitBasket : QObject { - \Q_OBJECT - QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_REPLACE_IF_NOT_DEFAULT - Q_PROPERTY(QQmlListProperty fruit READ fruit) - - public: - // ... - QQmlListProperty fruit(); - // ... - }; - \endcode + \snippet code/src_qml_qqmllist.cpp 1 \sa QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_APPEND \sa QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_REPLACE @@ -488,18 +466,7 @@ QML list properties are type-safe - in this case \c {Fruit} is a QObject type th When assigning the property in a derived type, the values replace those of the base class. - \code - class FruitBasket : QObject { - \Q_OBJECT - QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_REPLACE - Q_PROPERTY(QQmlListProperty fruit READ fruit) - - public: - // ... - QQmlListProperty fruit(); - // ... - }; - \endcode + \snippet code/src_qml_qqmllist.cpp 2 \sa QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_APPEND \sa QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_REPLACE_IF_NOT_DEFAULT diff --git a/src/qml/qml/qqmlparserstatus.cpp b/src/qml/qml/qqmlparserstatus.cpp index cd45e6668b..d2aa679a95 100644 --- a/src/qml/qml/qqmlparserstatus.cpp +++ b/src/qml/qml/qqmlparserstatus.cpp @@ -68,19 +68,7 @@ QT_BEGIN_NAMESPACE To use QQmlParserStatus, you must inherit both a QObject-derived class and QQmlParserStatus, and use the Q_INTERFACES() macro. - \code - class MyObject : public QObject, public QQmlParserStatus - { - \Q_OBJECT - Q_INTERFACES(QQmlParserStatus) - - public: - MyObject(QObject *parent = 0); - ... - void classBegin(); - void componentComplete(); - } - \endcode + \snippet code/src_qml_qqmlparserstatus.cpp 0 */ /*! \internal */ -- cgit v1.2.3