From a91423d4ce68d4520e97d12b204897b5933e56f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20K=C3=B6hne?= Date: Tue, 19 Dec 2023 10:22:28 +0100 Subject: [PATCH] Doc: Use Qml DefaultProperty as example for Q_CLASSINFO Setting a DefaultProperty is arguably something more useful to people than the 'made up' version example. Also add more links to the relevant QML pages. Pick-to: 6.6 Change-Id: Id967df7ddf81511299f95b9fd24f56af671fb855 Reviewed-by: Fabian Kosmale (cherry picked from commit 98ba0d4e95353febd5a4b14fe2eb9cbd4259bf0a) Reviewed-by: Qt Cherry-pick Bot --- .../doc/snippets/code/doc_src_properties.cpp | 2 +- src/corelib/doc/src/objectmodel/properties.qdoc | 6 ++++-- src/corelib/kernel/qobject.cpp | 15 +++++++++------ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/corelib/doc/snippets/code/doc_src_properties.cpp b/src/corelib/doc/snippets/code/doc_src_properties.cpp index 4019fee583b..190a8437101 100644 --- a/src/corelib/doc/snippets/code/doc_src_properties.cpp +++ b/src/corelib/doc/snippets/code/doc_src_properties.cpp @@ -96,7 +96,7 @@ object->setProperty("priority", "VeryHigh"); //! [7] -Q_CLASSINFO("Version", "3.0.0") +Q_CLASSINFO("DefaultProperty", "content") //! [7] //! [8] diff --git a/src/corelib/doc/src/objectmodel/properties.qdoc b/src/corelib/doc/src/objectmodel/properties.qdoc index a05c21120cf..80a0c98cf95 100644 --- a/src/corelib/doc/src/objectmodel/properties.qdoc +++ b/src/corelib/doc/src/objectmodel/properties.qdoc @@ -277,7 +277,9 @@ Connected to the property system is an additional macro, Q_CLASSINFO(), that can be used to attach additional - \e{name}--\e{value} pairs to a class's meta-object, for example: + \e{name}--\e{value} pairs to a class's meta-object. This is + used for instance to mark a property as the \e default one + in the context of \l{QML Object Types}: \snippet code/doc_src_properties.cpp 7 @@ -299,5 +301,5 @@ and the general tips on implementing and using \l {Qt Bindable Properties}{bindable properties}. - \sa {Qt Bindable Properties} + \sa {Qt Bindable Properties}, {Defining QML Types from C++} */ diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 3fd588f47b5..a131caedeec 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -4417,19 +4417,22 @@ QDebug operator<<(QDebug dbg, const QObject *o) \relates QObject This macro associates extra information to the class, which is available - using QObject::metaObject(). Qt makes only limited use of this feature in - \l{Qt D-Bus} and \l{Qt Qml} modules. - - The extra information takes the form of a \a Name string and a \a Value - literal string. + using QObject::metaObject(). The extra information takes the form of a + \a Name string and a \a Value literal string. Example: \snippet code/src_corelib_kernel_qobject.cpp 35 + Qt makes use of the macro in \l{Qt D-Bus} and \l{Qt Qml} modules. + For instance, when defining \l{QML Object Types} in C++, you can + designate a property as the \e default one: + + \snippet code/doc_src_properties.cpp 7 + \sa QMetaObject::classInfo() \sa {Using Qt D-Bus Adaptors} - \sa {Extending QML} + \sa {Defining QML Types from C++} */ /*!