aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/doc/extras
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-11-15 09:37:51 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-11-16 09:33:16 +0100
commit671f9ed73ee174fe2ba96d7a1c2b267455ef367e (patch)
treea0d4bbb196b06decbd274ba412fd241bcf18a97f /sources/pyside6/doc/extras
parent74fa311186c9355b43af7c4e6812d14e4fde332c (diff)
Add a QmlSingleton decorator
Add a simple decorator function that stores the type in a list for the QmlElement decorator to use singleton registration. Task-number: PYSIDE-1709 Pick-to: 6.2 Change-Id: I075d583404bd60dc52b84c23a3d09e50d32a5a3a Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside6/doc/extras')
-rw-r--r--sources/pyside6/doc/extras/QtQml.QmlSingleton.rst25
-rw-r--r--sources/pyside6/doc/extras/QtQml.qmlRegisterSingletonType.rst2
2 files changed, 27 insertions, 0 deletions
diff --git a/sources/pyside6/doc/extras/QtQml.QmlSingleton.rst b/sources/pyside6/doc/extras/QtQml.QmlSingleton.rst
new file mode 100644
index 000000000..d3d3bf4a7
--- /dev/null
+++ b/sources/pyside6/doc/extras/QtQml.QmlSingleton.rst
@@ -0,0 +1,25 @@
+.. currentmodule:: PySide6.QtQml
+.. _QmlSingleton:
+
+QmlSingleton
+************
+
+.. py:decorator:: QmlSingleton
+
+Declares the decorated type to be a singleton in QML. This only takes effect if
+the type is a Q_OBJECT and is available in QML (by having a QmlElement decorator).
+The QQmlEngine will try to create a singleton instance using the type's default
+constructor.
+
+.. code-block:: python
+
+ QML_IMPORT_NAME = "com.library.name"
+ QML_IMPORT_MAJOR_VERSION = 1
+ QML_IMPORT_MINOR_VERSION = 0 # Optional
+
+ @QmlElement
+ @QmlSingleton
+ class ClassForQml(QObject):
+ # ...
+
+.. note:: The order of the decorators matters; ``QmlSingleton`` needs to be preceded by ``QmlElement``.
diff --git a/sources/pyside6/doc/extras/QtQml.qmlRegisterSingletonType.rst b/sources/pyside6/doc/extras/QtQml.qmlRegisterSingletonType.rst
index 83102bf86..32231a391 100644
--- a/sources/pyside6/doc/extras/QtQml.qmlRegisterSingletonType.rst
+++ b/sources/pyside6/doc/extras/QtQml.qmlRegisterSingletonType.rst
@@ -15,6 +15,8 @@ qmlRegisterSingletonType
This function registers a Python type as a singleton in the QML system.
+ Alternatively, the :ref:`QmlSingleton` decorator can be used.
+
.. py:function:: qmlRegisterSingletonType(pytype: type, uri: str, versionMajor: int, versionMinor: int, typeName: str, callback: object) -> int
:param type pytype: Python class