summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc/src/objectmodel/properties.qdoc
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/doc/src/objectmodel/properties.qdoc')
-rw-r--r--src/corelib/doc/src/objectmodel/properties.qdoc35
1 files changed, 26 insertions, 9 deletions
diff --git a/src/corelib/doc/src/objectmodel/properties.qdoc b/src/corelib/doc/src/objectmodel/properties.qdoc
index 39f5e80eaa..d1690c5908 100644
--- a/src/corelib/doc/src/objectmodel/properties.qdoc
+++ b/src/corelib/doc/src/objectmodel/properties.qdoc
@@ -53,16 +53,22 @@
\snippet code/doc_src_properties.cpp 1
+ Here is an example showing how to export member variables as Qt
+ properties using the \c MEMBER keyword.
+ Note that a \c NOTIFY signal must be specified to allow QML property bindings.
+
+ \snippet code/doc_src_properties.cpp 8
+
A property behaves like a class data member, but it has additional
features accessible through the \l {Meta-Object System}.
- \list
+ \list
- \li A \c READ accessor function is required. It is for reading the
- property value. Ideally, a const function is used for this purpose,
- and it must return either the property's type or a pointer or
- reference to that type. e.g., QWidget::focus is a read-only property
- with \c READ function, QWidget::hasFocus().
+ \li A \c READ accessor function is required if no \c MEMBER variable was
+ specified. It is for reading the property value. Ideally, a const function
+ is used for this purpose, and it must return either the property's type or a
+ pointer or reference to that type. e.g., QWidget::focus is a read-only
+ property with \c READ function, QWidget::hasFocus().
\li A \c WRITE accessor function is optional. It is for setting the
property value. It must return void and must take exactly one
@@ -71,6 +77,13 @@
QWidget::setEnabled(). Read-only properties do not need \c WRITE
functions. e.g., QWidget::focus has no \c WRITE function.
+ \li A \c MEMBER variable association is required if no \c READ accessor
+ function is specified. This makes the given member variable
+ readable and writable without the need of creating \c READ and \c WRITE accessor
+ functions. It's still possible to use \c READ or \c WRITE accessor functions in
+ addition to \c MEMBER variable association (but not both), if you need to
+ control the variable access.
+
\li A \c RESET function is optional. It is for setting the property
back to its context specific default value. e.g., QWidget::cursor
has the typical \c READ and \c WRITE functions, QWidget::cursor()
@@ -82,10 +95,14 @@
\li A \c NOTIFY signal is optional. If defined, it should specify one
existing signal in that class that is emitted whenever the value
of the property changes.
+ \c NOTIFY signals for \c MEMBER variables must take zero or one parameter,
+ which must be of the same type as the property. The parameter will take the
+ new value of the property.
\li A \c REVISION number is optional. If included, it defines
the property and its notifier signal to be used in a particular
- revision of the API that is exposed to QML.
+ revision of the API (usually for exposure to QML). If not included, it
+ defaults to 0.
\li The \c DESIGNABLE attribute indicates whether the property
should be visible in the property editor of GUI design tool (e.g.,
@@ -114,7 +131,7 @@
gets and sets a widget's \c USER property.
\li The presence of the \c CONSTANT attibute indicates that the property
- value is constant. For a given object instance, the READ method of a
+ value is constant. For a given object instance, the READ method of a
constant property must return the same value every time it is called. This
constant value may be different for different instances of the object. A
constant property cannot have a WRITE method or a NOTIFY signal.
@@ -256,7 +273,7 @@
Q_DECLARE_METATYPE() macro so that their values can be stored in
QVariant objects. This makes them suitable for use with both
static properties declared using the Q_PROPERTY() macro in class
- definitions and dynamic properties created at run-time.
+ definitions and dynamic properties created at run-time.
\sa Q_DECLARE_METATYPE(), QMetaType, QVariant