diff options
author | Ulf Hermann <[email protected]> | 2020-02-17 14:15:49 +0100 |
---|---|---|
committer | Ulf Hermann <[email protected]> | 2020-02-24 10:27:17 +0100 |
commit | 130c26023b56469f4274c4c0b039acd20ac3988b (patch) | |
tree | e67ef89551979a43e8ea41ff8f021704d814e2cf | |
parent | b3ff342d327dc00d99281dca4fbfe6c4300aa6c6 (diff) |
Doc: Fix documentation from QQmlEngine::singletonInstance()
Don't suggest procedural registration of C++ types.
Change-Id: Ib133fa7557f7555222fc55344a29967efc5c1f6f
Reviewed-by: Fabian Kosmale <[email protected]>
Reviewed-by: Simon Hausmann <[email protected]>
-rw-r--r-- | src/qml/qml/qqmlengine.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index f97612ab75..ad57b1f74b 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -1360,12 +1360,16 @@ void QQmlEngine::setOutputWarningsToStandardError(bool enabled) \code class MySingleton : public QObject { Q_OBJECT + + // Register as default constructed singleton. + QML_ELEMENT + QML_SINGLETON + static int typeId; // ... }; - // Register with QObject* callback - MySingleton::typeId = qmlRegisterSingletonType<MySingleton>(...); + MySingleton::typeId = qmlTypeId(...); // Retrieve as QObject* QQmlEngine engine; @@ -1382,11 +1386,10 @@ void QQmlEngine::setOutputWarningsToStandardError(bool enabled) QJSValue instance = engine.singletonInstance<QJSValue>(typeId); \endcode - It is recommended to store the QML type id during registration, e.g. as a static member - in the singleton class. Otherwise, a costly lookup via qmlTypeId() has to be performed - at run-time. + 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. - \sa qmlRegisterSingletonType(), qmlTypeId() + \sa QML_SINGLETON, qmlRegisterSingletonType(), qmlTypeId() \since 5.12 */ template<> |