diff options
-rw-r--r-- | src/qml/doc/src/qmlfunctions.qdoc | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/qml/doc/src/qmlfunctions.qdoc b/src/qml/doc/src/qmlfunctions.qdoc index 82d85a1472..34dce8f4da 100644 --- a/src/qml/doc/src/qmlfunctions.qdoc +++ b/src/qml/doc/src/qmlfunctions.qdoc @@ -282,6 +282,74 @@ system. Instances of this type cannot be created from the QML system. + This function should be used when the type will not be referenced by name. + Specifically, it has to be used for C++ types that are used as the left-hand + side of a property binding. + + For example, consider the following two classes: + + \code + class Bar : public QObject + { + Q_OBJECT + Q_PROPERTY(QString baz READ baz WRITE setBaz NOTIFY bazChanged) + + public: + Bar() {} + + QString baz() const { return mBaz; } + + void setBaz(const QString &baz) + { + if (baz == mBaz) + return; + + mBaz = baz; + emit bazChanged(); + } + + signals: + void bazChanged(); + + private: + QString mBaz; + }; + + class Foo : public QObject + { + Q_OBJECT + Q_PROPERTY(Bar *bar READ bar CONSTANT FINAL) + + public: + Foo() {} + + Bar *bar() { return &mBar; } + + private: + Bar mBar; + }; + \endcode + + In QML, we assign a string to the \c baz property of \c bar: + + \code + Foo { + bar.baz: "abc" + Component.onCompleted: print(bar.baz) + } + \endcode + + For the QML engine to know that the \c Bar type has a \c baz property, + we have to make \c Bar known: + + \code + qmlRegisterType<Foo>("App", 1, 0, "Foo"); + qmlRegisterType<Bar>(); + \code + + As the \c Foo type is instantiated in QML, it must be registered + with the version of \l qmlRegisterType() that takes an import URI. + Returns the QML type id. \sa {Choosing the Correct Integration Method Between C++ and QML} |