aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2023-02-16 09:39:24 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-02-17 20:07:01 +0000
commit53f64f76f430440dd1bd2e5d5b0dbdab6801b8c8 (patch)
tree6fc627cbd637ae9be62905f1eaef7e37f57bcc7a
parentb9db5246bc99d9438aa88142cb9144bda9e97bf3 (diff)
Doc: How to combine custom singletons and qt_generate_foreign_qml_types
First, make it more explicit that the QML engine really wants to own the singletons. Then explain how to combine qt_generate_foreign_qml_types with custom types you need to manually manage. Fixes: QTBUG-111169 Change-Id: I9e070c3482014691382c9c1279c918913bdf0307 Reviewed-by: Sze Howe Koh <szehowe.koh@gmail.com> (cherry picked from commit 4f33440a6ce19fcd2a98a77dced76f874d8625c3) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/qml/doc/src/cmake/qt_generate_foreign_qml_types.qdoc9
-rw-r--r--src/qml/doc/src/qmlfunctions.qdoc4
2 files changed, 12 insertions, 1 deletions
diff --git a/src/qml/doc/src/cmake/qt_generate_foreign_qml_types.qdoc b/src/qml/doc/src/cmake/qt_generate_foreign_qml_types.qdoc
index c69b618df4..9bd412d36d 100644
--- a/src/qml/doc/src/cmake/qt_generate_foreign_qml_types.qdoc
+++ b/src/qml/doc/src/cmake/qt_generate_foreign_qml_types.qdoc
@@ -67,4 +67,13 @@ the \c QML_ELEMENT macro).
The effect is equivalent to using \c QML_FOREIGN with custom structs in the QML library to expose
the types.
+
+\note In order to implement custom behavior, such as exposing an existing
+singleton instance with its own life cycle to QML, you should add custom types
+to your QML library (mylib_declarative in the above example). In turn, you
+should omit the \l QML_ELEMENT and similar macros from the original C++ classes
+so that qt_generate_foreign_qml_types() does not generate more QML integration
+structs for them. The QML macros, as well as any singleton factory functions,
+can be added to the structs that contain the \l QML_FOREIGN.
+
*/
diff --git a/src/qml/doc/src/qmlfunctions.qdoc b/src/qml/doc/src/qmlfunctions.qdoc
index 7995f03674..005bd0be94 100644
--- a/src/qml/doc/src/qmlfunctions.qdoc
+++ b/src/qml/doc/src/qmlfunctions.qdoc
@@ -173,7 +173,9 @@
\c{T *create(QQmlEngine *, QJSEngine *)} when the type is first accessed.
If both do exist and are accessible, the default constructor is preferred.
If there is no default constructor and no factory function the singleton is
- inaccessible.
+ inaccessible. The QML engine generally assumes ownership of the singleton and
+ will delete it when the engine itself is destroyed. You can prevent this by
+ calling QJSEngine::setObjectOwnership() on the singleton.
In order to declare a default-constructible class as singleton, all you have
to do is add \l QML_SINGLETON: