1 | //! [0]
|
---|
2 | struct MyStructure
|
---|
3 | {
|
---|
4 | int count;
|
---|
5 | QString name;
|
---|
6 | };
|
---|
7 | QT_DECLARE_METATYPE(MyStructure)
|
---|
8 |
|
---|
9 | // Marshall the MyStructure data into a D-Bus argument
|
---|
10 | QDBusArgument &operator<<(QDBusArgument &argument, const MyStructure &mystruct)
|
---|
11 | {
|
---|
12 | argument.beginStructure();
|
---|
13 | argument << mystruct.count << mystruct.name;
|
---|
14 | argument.endStructure();
|
---|
15 | return argument;
|
---|
16 | }
|
---|
17 |
|
---|
18 | // Retrieve the MyStructure data from the D-Bus argument
|
---|
19 | const QDBusArgument &operator>>(const QDBusArgument &argument, MyStructure &mystruct)
|
---|
20 | {
|
---|
21 | argument.beginStructure();
|
---|
22 | argument >> mystruct.count >> mystruct.name;
|
---|
23 | argument.endStructure();
|
---|
24 | return argument;
|
---|
25 | }
|
---|
26 | //! [0]
|
---|
27 |
|
---|
28 |
|
---|
29 | //! [1]
|
---|
30 | qDBusRegisterMetaType<MyStructure>();
|
---|
31 | //! [1]
|
---|
32 |
|
---|
33 |
|
---|
34 | //! [2]
|
---|
35 | MyType item = qdbus_cast<Type>(argument);
|
---|
36 | //! [2]
|
---|
37 |
|
---|
38 |
|
---|
39 | //! [3]
|
---|
40 | MyType item;
|
---|
41 | argument >> item;
|
---|
42 | //! [3]
|
---|
43 |
|
---|
44 |
|
---|
45 | //! [4]
|
---|
46 | QDBusArgument &operator<<(QDBusArgument &argument, const MyStructure &mystruct)
|
---|
47 | {
|
---|
48 | argument.beginStructure();
|
---|
49 | argument << mystruct.member1 << mystruct.member2 << ... ;
|
---|
50 | argument.endStructure();
|
---|
51 | return argument;
|
---|
52 | }
|
---|
53 | //! [4]
|
---|
54 |
|
---|
55 |
|
---|
56 | //! [5]
|
---|
57 | QDBusArgument &operator<<(QDBusArgument &argument, const MyStructure &mystruct)
|
---|
58 | {
|
---|
59 | argument.beginStructure();
|
---|
60 | argument << mystruct.member1 << mystruct.member2;
|
---|
61 |
|
---|
62 | argument.beginStructure();
|
---|
63 | argument << mystruct.member3.subMember1 << mystruct.member3.subMember2;
|
---|
64 | argument.endStructure();
|
---|
65 |
|
---|
66 | argument << mystruct.member4;
|
---|
67 | argument.endStructure();
|
---|
68 | return argument;
|
---|
69 | }
|
---|
70 | //! [5]
|
---|
71 |
|
---|
72 |
|
---|
73 | //! [6]
|
---|
74 | // append an array of MyElement types
|
---|
75 | QDBusArgument &operator<<(QDBusArgument &argument, const MyArray &myarray)
|
---|
76 | {
|
---|
77 | argument.beginArray( qMetaTypeId<MyElement>() );
|
---|
78 | for ( int i = 0; i < myarray.length; ++i )
|
---|
79 | argument << myarray.elements[i];
|
---|
80 | argument.endArray();
|
---|
81 | return argument;
|
---|
82 | }
|
---|
83 | //! [6]
|
---|
84 |
|
---|
85 |
|
---|
86 | //! [7]
|
---|
87 | // append a dictionary that associates ints to MyValue types
|
---|
88 | QDBusArgument &operator<<(QDBusArgument &argument, const MyDictionary &mydict)
|
---|
89 | {
|
---|
90 | argument.beginMap( QVariant::Int, qMetaTypeId<MyValue>() );
|
---|
91 | for ( int i = 0; i < mydict.length; ++i ) {
|
---|
92 | argument.beginMapEntry();
|
---|
93 | argument << mydict.data[i].key << mydict.data[i].value;
|
---|
94 | argument.endMapEntry();
|
---|
95 | }
|
---|
96 | argument.endMap();
|
---|
97 | return argument;
|
---|
98 | }
|
---|
99 | //! [7]
|
---|
100 |
|
---|
101 |
|
---|
102 | //! [8]
|
---|
103 | const QDBusArgument &operator>>(const QDBusArgument &argument, MyStructure &mystruct)
|
---|
104 | {
|
---|
105 | argument.beginStructure()
|
---|
106 | argument >> mystruct.member1 >> mystruct.member2 >> mystruct.member3 >> ...;
|
---|
107 | argument.endStructure();
|
---|
108 | return argument;
|
---|
109 | }
|
---|
110 | //! [8]
|
---|
111 |
|
---|
112 |
|
---|
113 | //! [9]
|
---|
114 | // extract a MyArray array of MyElement elements
|
---|
115 | const QDBusArgument &operator>>(const QDBusArgument &argument, MyArray &myarray)
|
---|
116 | {
|
---|
117 | argument.beginArray();
|
---|
118 | myarray.clear();
|
---|
119 |
|
---|
120 | while ( !argument.atEnd() ) {
|
---|
121 | MyElement element;
|
---|
122 | argument >> element;
|
---|
123 | myarray.append( element );
|
---|
124 | }
|
---|
125 |
|
---|
126 | argument.endArray();
|
---|
127 | return argument;
|
---|
128 | }
|
---|
129 | //! [9]
|
---|
130 |
|
---|
131 |
|
---|
132 | //! [10]
|
---|
133 | // extract a MyDictionary map that associates ints to MyValue elements
|
---|
134 | const QDBusArgument &operator>>(const QDBusArgument &argument, MyDictionary &mydict)
|
---|
135 | {
|
---|
136 | argument.beginMap();
|
---|
137 | mydict.clear();
|
---|
138 |
|
---|
139 | while ( !argMap.atEnd() ) {
|
---|
140 | int key;
|
---|
141 | MyValue value;
|
---|
142 | argument.beginMapEntry();
|
---|
143 | argument >> key >> value;
|
---|
144 | argument.endMapEntry();
|
---|
145 | mydict.append( key, value );
|
---|
146 | }
|
---|
147 |
|
---|
148 | argument.endMap();
|
---|
149 | return argument;
|
---|
150 | }
|
---|
151 | //! [10]
|
---|