source: trunk/doc/src/snippets/code/doc_src_properties.qdoc@ 5

Last change on this file since 5 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 1.5 KB
Line 
1//! [0]
2Q_PROPERTY(type name
3 READ getFunction
4 [WRITE setFunction]
5 [RESET resetFunction]
6 [DESIGNABLE bool]
7 [SCRIPTABLE bool]
8 [STORED bool]
9 [USER bool])
10//! [0]
11
12
13//! [1]
14Q_PROPERTY(bool focus READ hasFocus)
15Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
16Q_PROPERTY(QCursor cursor READ cursor WRITE setCursor RESET unsetCursor)
17//! [1]
18
19
20//! [2]
21Q_PROPERTY(QDate date READ getDate WRITE setDate)
22//! [2]
23
24
25//! [3]
26QPushButton *button = new QPushButton;
27QObject *object = button;
28
29button->setDown(true);
30object->setProperty("down", true);
31//! [3]
32
33
34//! [4]
35QObject *object = ...
36const QMetaObject *metaobject = object->metaObject();
37int count = metaobject->propertyCount();
38for (int i=0; i<count; ++i) {
39 QMetaProperty metaproperty = metaobject->property(i);
40 const char *name = metaproperty.name();
41 QVariant value = object->property(name);
42 ...
43}
44//! [4]
45
46
47//! [5]
48class MyClass : public QObject
49{
50 Q_OBJECT
51 Q_PROPERTY(Priority priority READ priority WRITE setPriority)
52 Q_ENUMS(Priority)
53
54public:
55 MyClass(QObject *parent = 0);
56 ~MyClass();
57
58 enum Priority { High, Low, VeryHigh, VeryLow };
59
60 void setPriority(Priority priority);
61 Priority priority() const;
62};
63//! [5]
64
65
66//! [6]
67MyClass *myinstance = new MyClass;
68QObject *object = myinstance;
69
70myinstance->setPriority(MyClass::VeryHigh);
71object->setProperty("priority", "VeryHigh");
72//! [6]
73
74
75//! [7]
76Q_CLASSINFO("Version", "3.0.0")
77//! [7]
Note: See TracBrowser for help on using the repository browser.