Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
src_qdbus_qdbusargument.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include <QString>
5#include <QDBusArgument>
6#include <QDBusMetaType>
7#include <QDBusMessage>
8#include <QDBusContext>
9
11typedef QList<MyElement> MyArray;
12typedef QHash<int, MyElement> MyDictionary;
17
18class MyObject: public QObject
19{
21
22 Q_CLASSINFO("D-Bus Interface", "org.qtproject.QtDBus.MyObject")
23 Q_CLASSINFO("D-Bus Introspection", ""
24" <interface name=\"org.qtproject.QtDBus.MyObject\" >\n"
25" <property access=\"readwrite\" type=\"i\" name=\"prop1\" />\n"
26" <property name=\"complexProp\" type=\"ai\" access=\"readwrite\">\n"
27" <annotation name=\"org.qtproject.QtDBus.QtTypeName\" value=\"QList&lt;int&gt;\"/>\n"
28" </property>\n"
29" <signal name=\"somethingHappened\" >\n"
30" <arg direction=\"out\" type=\"s\" />\n"
31" </signal>\n"
32" <method name=\"ping\" >\n"
33" <arg direction=\"in\" type=\"v\" name=\"ping\" />\n"
34" <arg direction=\"out\" type=\"v\" name=\"ping\" />\n"
35" </method>\n"
36" <method name=\"ping_invokable\" >\n"
37" <arg direction=\"in\" type=\"v\" name=\"ping_invokable\" />\n"
38" <arg direction=\"out\" type=\"v\" name=\"ping_invokable\" />\n"
39" </method>\n"
40" <method name=\"ping\" >\n"
41" <arg direction=\"in\" type=\"v\" name=\"ping1\" />\n"
42" <arg direction=\"in\" type=\"v\" name=\"ping2\" />\n"
43" <arg direction=\"out\" type=\"v\" name=\"pong1\" />\n"
44" <arg direction=\"out\" type=\"v\" name=\"pong2\" />\n"
45" </method>\n"
46" <method name=\"ping_invokable\" >\n"
47" <arg direction=\"in\" type=\"v\" name=\"ping1_invokable\" />\n"
48" <arg direction=\"in\" type=\"v\" name=\"ping2_invokable\" />\n"
49" <arg direction=\"out\" type=\"v\" name=\"pong1_invokable\" />\n"
50" <arg direction=\"out\" type=\"v\" name=\"pong2_invokable\" />\n"
51" </method>\n"
52" <method name=\"ping\" >\n"
53" <arg direction=\"in\" type=\"ai\" name=\"ping\" />\n"
54" <arg direction=\"out\" type=\"ai\" name=\"ping\" />\n"
55" <annotation name=\"org.qtproject.QtDBus.QtTypeName.In0\" value=\"QList&lt;int&gt;\"/>\n"
56" <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"QList&lt;int&gt;\"/>\n"
57" </method>\n"
58" <method name=\"ping_invokable\" >\n"
59" <arg direction=\"in\" type=\"ai\" name=\"ping_invokable\" />\n"
60" <arg direction=\"out\" type=\"ai\" name=\"ping_invokable\" />\n"
61" <annotation name=\"org.qtproject.QtDBus.QtTypeName.In0\" value=\"QList&lt;int&gt;\"/>\n"
62" <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"QList&lt;int&gt;\"/>\n"
63" </method>\n"
64" </interface>\n"
65 "")
66 Q_PROPERTY(int prop1 READ prop1 WRITE setProp1)
67 Q_PROPERTY(QList<int> complexProp READ complexProp WRITE setComplexProp)
68
69public:
70 static int callCount;
71 static QVariantList callArgs;
72 MyObject()
73 {
74 QObject *subObject = new QObject(this);
75 subObject->setObjectName("subObject");
76 }
77};
78
80{
83};
84
99
100// Marshall the MyStructure data into a D-Bus argument
101QDBusArgument &operator<<(QDBusArgument &argument, const MyStructure &myStruct)
102{
104 argument << myStruct.count << myStruct.name;
106 return argument;
107}
108
109// Retrieve the MyStructure data from the D-Bus argument
111{
113 argument >> myStruct.count >> myStruct.name;
115 return argument;
116}
118
119const QDBusArgument &operator<<(const QDBusArgument &argument, const MyMember &/*member*/)
120{
121 return argument;
122}
123
124const QDBusArgument &operator>>(const QDBusArgument &argument, const MyMember &/*member*/)
125{
126 return argument;
127}
128
130{
132qDBusRegisterMetaType<MyStructure>();
134}
135
137{
138QVariant argument = MyObject::callArgs.at(0);
139QDBusVariant dv = qdbus_cast<QDBusVariant>(argument);
141MyType item = qdbus_cast<Type>(argument);
143}
144
146{
149argument >> item;
151}
153{
156{
158 argument << myStruct.member1 << myStruct.member2;
160 return argument;
161}
163
164namespace Alt {
167{
169 argument << myStruct.member1 << myStruct.member2;
170
172 argument << myStruct.member3.subMember1 << myStruct.member3.subMember2;
174
175 argument << myStruct.member4;
177 return argument;
178}
180} // namespace
181
183// Append an array of MyElement types
185{
186 argument.beginArray(qMetaTypeId<MyElement>());
187 for (const auto &element : myArray)
188 argument << element;
190 return argument;
191}
193
195// Append a dictionary that associates ints to MyValue types
197{
198 argument.beginMap(QMetaType::fromType<int>(), QMetaType::fromType<MyValue>());
199 MyDictionary::const_iterator i;
200 for (i = myDict.cbegin(); i != myDict.cend(); ++i) {
202 argument << i.key() << i.value();
204 }
206 return argument;
207}
209
212{
214 argument >> myStruct.member1 >> myStruct.member2 >> myStruct.member3;
216 return argument;
217}
219
221// Extract a MyArray array of MyElement elements
223{
225 myArray.clear();
226
227 while (!argument.atEnd()) {
228 MyElement element;
229 argument >> element;
230 myArray.append(element);
231 }
232
234 return argument;
235}
237
239// Extract a MyDictionary map that associates integers to MyElement items
241{
243 myDict.clear();
244
245 while (!argument.atEnd()) {
246 int key;
249 argument >> key >> value;
251 myDict.insert(key, value);
252 }
253
255 return argument;
256}
258}
\inmodule QtDBus
void beginMapEntry()
Opens a D-Bus map entry suitable for appending the key and value entries.
void endArray()
Closes a D-Bus array opened with beginArray().
void endMapEntry()
Closes a D-Bus map entry opened with beginMapEntry().
void beginStructure()
Opens a new D-Bus structure suitable for appending new arguments.
void endMap()
Closes a D-Bus map opened with beginMap().
bool atEnd() const
Returns true if there are no more elements to be extracted from this QDBusArgument.
void endStructure()
Closes a D-Bus structure opened with beginStructure().
void beginArray(int elementMetaTypeId)
void beginMap(int keyMetaTypeId, int valueMetaTypeId)
\inmodule QtDBus
\inmodule QtCore
Definition qobject.h:103
Q_INVOKABLE QObject(QObject *parent=nullptr)
Constructs an object with parent object parent.
Definition qobject.cpp:936
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qvariant.h:65
QDBusArgument & operator<<(QDBusArgument &argument, const MyStructure &myStruct)
[5]
QDBusArgument & operator<<(QDBusArgument &argument, const MyStructure &myStruct)
[4]
const QDBusArgument & operator>>(const QDBusArgument &argument, MyStructure &myStruct)
[7]
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define Q_DECLARE_METATYPE(TYPE)
Definition qmetatype.h:1525
GLuint64 key
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_CLASSINFO(name, value)
QGraphicsItem * item
const QDBusArgument & operator>>(const QDBusArgument &argument, MyStructure &myStruct)
void castType()
QDBusArgument & operator<<(QDBusArgument &argument, const MyStructure &myStruct)
QDBusVariant MyType
QHash< int, MyElement > MyDictionary
QDBusVariant Type
void argumentItem()
void registerMyStructure()
QList< MyElement > MyArray
QDBusVariant MyElement
QDBusArgument argument
QDBusVariant MyValue