aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/doc/src
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2021-12-01 13:10:00 +0100
committerAlexandru Croitor <alexandru.croitor@qt.io>2021-12-03 08:20:52 +0100
commit34efbd202287b0fd0611b48938a1678edb2b2e45 (patch)
tree0e9b28fe393af34f870e9eea8b8de198e78f2432 /src/qml/doc/src
parentfa60900205a2f6ace81273a404cbcb93e04d211a (diff)
doc: Add a section about singleton types in qt_add_qml_module
QT_QML_SINGLETON_TYPE was only documented on the qt_target_qml_sources page. Add a short section about singletons to the qt_add_qml_module page and reference the other page. Adjust the example in qt_target_qml_sources to show case how to set the singleton source property. Pick-to: 6.2 Fixes: QTBUG-97541 Change-Id: I11aa3cb7c0feb748eba1d7ac9ef81a8ac6cb16b1 Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Diffstat (limited to 'src/qml/doc/src')
-rw-r--r--src/qml/doc/src/cmake/qt_add_qml_module.qdoc12
-rw-r--r--src/qml/doc/src/cmake/qt_target_qml_sources.qdoc9
2 files changed, 21 insertions, 0 deletions
diff --git a/src/qml/doc/src/cmake/qt_add_qml_module.qdoc b/src/qml/doc/src/cmake/qt_add_qml_module.qdoc
index b9d5052cf0..f7690e89d6 100644
--- a/src/qml/doc/src/cmake/qt_add_qml_module.qdoc
+++ b/src/qml/doc/src/cmake/qt_add_qml_module.qdoc
@@ -269,6 +269,18 @@ target will be the \c target followed by \c{_qmllint}. An \c{all_qmllint}
target which depends on all the individual \c{*_qmllint} targets is also
provided as a convenience.
+\target qml-cmake-singletons
+\section2 Singletons
+
+If a QML module has \c{.qml} files which provide singleton types, these files
+need to have their \c QT_QML_SINGLETON_TYPE source property set to \c TRUE, to
+ensure that the \singleton command is written into the
+\l{Module Definition qmldir Files}{qmldir} file. This must be done in addition
+to the QML file containing the \c {pragma Singleton} statement.
+
+See \l{qt_target_qml_sources_example}{qt_target_qml_sources()} for an example on
+how to set the \c QT_QML_SINGLETON_TYPE property.
+
\section1 Arguments
The \c target specifies the name of the backing target for the QML module.
diff --git a/src/qml/doc/src/cmake/qt_target_qml_sources.qdoc b/src/qml/doc/src/cmake/qt_target_qml_sources.qdoc
index 63f9e86e66..c5a7212caa 100644
--- a/src/qml/doc/src/cmake/qt_target_qml_sources.qdoc
+++ b/src/qml/doc/src/cmake/qt_target_qml_sources.qdoc
@@ -193,6 +193,7 @@ can be overridden by setting the \c QT_RESOURCE_ALIAS property on the source
file. This is commonly used to collect files from different directories and
have them appear in the resources under a common location.
+\target qt_target_qml_sources_example
\snippet cmake/qt_target_qml_sources/CMakeLists.txt 0
In the above example, the \c qt_target_qml_sources_example target's resources
@@ -200,6 +201,7 @@ will end up with the following contents:
\list
\li \c{/my.company.com/imports/Example/File.qml}
+\li \c{/my.company.com/imports/Example/FunnySingleton.qml}
\li \c{/my.company.com/imports/Example/templates/File.qml}
\li \c{/my.company.com/imports/Example/some_old_thing.qml}
\li \c{/my.company.com/imports/Example/button-types.png}
@@ -210,8 +212,15 @@ The generated \c qmldir file will contain the following type entries:
\badcode
File 2.0 File.qml
+singleton FunnySingleton 2.0 FunnySingleton.qml
OldThing 1.1 some_old_thing.qml
OldThing 2.0 some_old_thing.qml
\endcode
+\note The source FunnySingleton.qml file must already contain
+the \c {pragma Singleton} statement. Setting the \c QT_QML_SINGLETON_TYPE source
+property does not automatically generate the pragma.
+
+\snippet cmake/qt_target_qml_sources/FunnySingleton.qml 0
+
*/