aboutsummaryrefslogtreecommitdiffstats
path: root/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp
blob: 046b40ce0142faa1f74299a5ae622e8ef5d9207d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

void wrapInFunction()
{

//! [0]
class MyClass:

    Q_CLASSINFO("author", "Sabrina Schweinsteiger")
    Q_CLASSINFO("url", "http://doc.moosesoft.co.uk/1.0/")

    ...
//! [0]


//! [1]
normType = QMetaObject.normalizedType(" int    const  *")
# normType is now "const int*"
//! [1]


//! [2]
QMetaObject.invokeMethod(pushButton, "animateClick",
                         Qt.QueuedConnection)
//! [2]


//! [3]
QMetaObject.invokeMethod: Unable to handle unregistered datatype 'MyType'
//! [3]


//! [4]
retVal = QString()
QMetaObject.invokeMethod(obj, "compute", Qt::DirectConnection,
                         Q_RETURN_ARG(QString, retVal),
                         Q_ARG(QString, "sqrt"),
                         Q_ARG(int, 42),
                         Q_ARG(double, 9.7));
//! [4]


//! [5]
class MyClass:
    Q_CLASSINFO("author", "Sabrina Schweinsteiger")
    Q_CLASSINFO("url", "http://doc.moosesoft.co.uk/1.0/")
//! [5]


//! [propertyCount]
metaObject = obj.metaObject()
properties = [metaObject.property(i).name() for i in range(metaObject.propertyOffset(), metaObject.propertyCount())]
//! [propertyCount]


//! [methodCount]
metaObject = obj.metaObject()
methods = [metaObject.method(i).signature() for i in range(metaObject.methodOffset(), metaObject.methodCount())]
//! [methodCount]

//! [6]
methodIndex = pushButton.metaObject().indexOfMethod("animateClick()")
method = metaObject.method(methodIndex)
method.invoke(pushButton, Qt.QueuedConnection)
//! [6]

//! [7]
QMetaMethod.invoke: Unable to handle unregistered datatype 'MyType'
//! [7]

//! [8]
retVal = QString()
normalizedSignature = QMetaObject.normalizedSignature("compute(QString, int, double)")
methodIndex = obj.metaObject().indexOfMethod(normalizedSignature)
method = metaObject.method(methodIndex)
method.invoke(obj,
              Qt.DirectConnection,
              Q_RETURN_ARG(QString, retVal),
              Q_ARG(QString, "sqrt"),
              Q_ARG(int, 42),
              Q_ARG(double, 9.7));
//! [8]

}