diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-04-20 16:37:22 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-04-21 12:02:11 +0000 |
commit | 7a309179d4413be51065ce3dbb0a121da8a1b2a1 (patch) | |
tree | cc6dc2a8b263375194aadd6f45078e1aa4bb71e5 | |
parent | 71fdc7116ac43fc99aee414c0c58b462a8b5bc9e (diff) |
Expand QML_EXTENDED_NAMSPACE's documentation
Note that it doesn't necessarily need a namespace; mention that it
however requires the "namespace" and its contained enums to be exposed
to the metaobject system to work.
Moreover, add a minimal code example.
Change-Id: I814c65b2b59747f902f2291e2f98962eb98d4d59
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
(cherry picked from commit a3959ea9df49b5c30833d49daede5bf60a70897e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/qml/doc/src/qmlfunctions.qdoc | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/qml/doc/src/qmlfunctions.qdoc b/src/qml/doc/src/qmlfunctions.qdoc index c454d981a3..f48a5f475b 100644 --- a/src/qml/doc/src/qmlfunctions.qdoc +++ b/src/qml/doc/src/qmlfunctions.qdoc @@ -264,9 +264,40 @@ Declares that the enclosing type uses \a EXTENDED_NAMESPACE as an extension to provide further enumerations in QML. This takes effect if the type is exposed to QML using a \l QML_ELEMENT or \l QML_NAMED_ELEMENT() macro. + The enumerations need to be exposed to the metaobject system for this to work. + + For example, give the following C++ code + \code + namespace MyNamespace { + Q_NAMESPACE + enum MyEnum { MyEnumerator = 10 }; + Q_ENUM_NS(MyEnum) + } + + class QmlType : public QObject + { + Q_OBJECT + QML_ELEMENT + QML_EXTENDED_NAMESPACE(MyNamespace) + } + \endcode + + we can access the enum in QML: + \qml + QmlType { + property int i: QmlType.MyEnumerator // i will be 10 + } + \endqml + + \note EXTENDED_NAMESPACE can also be a QObject or QGadget; in that case - and in contrast to + QML_EXTENDED, which also exposes methods and properties - only its enumerations + are exposed. + + \note \a EXTENDED_NAMESPACE must have a metaobject; i.e. it must either be a namespace which + contains the Q_NAMESPACE macro or a QObject/QGadget. \sa QML_ELEMENT, QML_NAMED_ELEMENT(), QML_EXTENDED(), - {Registering Extension Objects} + {Registering Extension Objects}, Q_ENUM, Q_ENUM_NS */ /*! |