summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc/snippets/code
diff options
context:
space:
mode:
authorGerhard Gappmeier <gerhard.gappmeier@ascolab.com>2012-07-02 13:01:32 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-01-19 17:36:55 +0100
commit9bbebb914422262b7b585b6d1dab9d21c4238c44 (patch)
tree65a87988bb8d2d8bae3e81bbff2dce480f436435 /src/corelib/doc/snippets/code
parent6f225b0b5d774828df310948435f1cc3a4720104 (diff)
Add support for defining properties from member variables.
This associates properties with member variables and avoids writing getter and setter methods manually. The metaCall() method directly accesses the member variable, so additional method calls can be avoided. The metaCall() setter code also supports NOTIFY signals, which means the according signal is emitted when the property gets written. Task-number: QTBUG-16852 Change-Id: I88a1f237ea53a1e9cf65fc9ef2e207718eb8b6c3 Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/doc/snippets/code')
-rw-r--r--src/corelib/doc/snippets/code/doc_src_properties.cpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/corelib/doc/snippets/code/doc_src_properties.cpp b/src/corelib/doc/snippets/code/doc_src_properties.cpp
index 7ee414e00e..a67cbb68aa 100644
--- a/src/corelib/doc/snippets/code/doc_src_properties.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_properties.cpp
@@ -40,8 +40,8 @@
//! [0]
Q_PROPERTY(type name
- READ getFunction
- [WRITE setFunction]
+ (READ getFunction [WRITE setFunction] |
+ MEMBER memberName [(READ getFunction | WRITE setFunction)])
[RESET resetFunction]
[NOTIFY notifySignal]
[REVISION int]
@@ -130,3 +130,20 @@ object->setProperty("priority", "VeryHigh");
//! [7]
Q_CLASSINFO("Version", "3.0.0")
//! [7]
+
+//! [8]
+ Q_PROPERTY(QColor color MEMBER m_color NOTIFY colorChanged)
+ Q_PROPERTY(qreal spacing MEMBER m_spacing NOTIFY spacingChanged)
+ Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged)
+ ...
+signals:
+ void colorChanged();
+ void spacingChanged();
+ void textChanged(const QString &newText);
+
+private:
+ QColor m_color;
+ qreal m_spacing;
+ QString m_text;
+//! [8]
+