diff options
Diffstat (limited to 'sources/pyside6/doc/extras/QtQml.QmlSingleton.rst')
-rw-r--r-- | sources/pyside6/doc/extras/QtQml.QmlSingleton.rst | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/sources/pyside6/doc/extras/QtQml.QmlSingleton.rst b/sources/pyside6/doc/extras/QtQml.QmlSingleton.rst index d3d3bf4a7..402c18d55 100644 --- a/sources/pyside6/doc/extras/QtQml.QmlSingleton.rst +++ b/sources/pyside6/doc/extras/QtQml.QmlSingleton.rst @@ -1,13 +1,8 @@ .. 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 type is a QObject 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. @@ -20,6 +15,19 @@ constructor. @QmlElement @QmlSingleton class ClassForQml(QObject): - # ... + ... + +It is also possible to use a static ``create()`` method which receives +the engine as a parameter: + +.. code-block:: python + + @QmlElement + @QmlSingleton + class ClassForQml(QObject): + + @staticmethod + def create(engine): + ... .. note:: The order of the decorators matters; ``QmlSingleton`` needs to be preceded by ``QmlElement``. |