QtBase  v6.3.1
myobject.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28 
29 #ifndef MYOBJECT_H
30 #define MYOBJECT_H
31 
32 #include <QObject>
33 #include <QDBusMessage>
34 #include <QDBusContext>
35 #include <QDBusConnection>
36 
37 class MyObject: public QObject, protected QDBusContext
38 {
39  Q_OBJECT
40  Q_CLASSINFO("D-Bus Interface", "org.qtproject.QtDBus.MyObject")
41  Q_CLASSINFO("D-Bus Introspection", ""
42 " <interface name=\"org.qtproject.QtDBus.MyObject\" >\n"
43 " <property access=\"readwrite\" type=\"i\" name=\"prop1\" />\n"
44 " <property name=\"complexProp\" type=\"ai\" access=\"readwrite\">\n"
45 " <annotation name=\"org.qtproject.QtDBus.QtTypeName\" value=\"QList&lt;int&gt;\"/>\n"
46 " </property>\n"
47 " <signal name=\"somethingHappened\" >\n"
48 " <arg direction=\"out\" type=\"s\" />\n"
49 " </signal>\n"
50 " <method name=\"ping\" >\n"
51 " <arg direction=\"in\" type=\"v\" name=\"ping\" />\n"
52 " <arg direction=\"out\" type=\"v\" name=\"ping\" />\n"
53 " </method>\n"
54 " <method name=\"ping_invokable\" >\n"
55 " <arg direction=\"in\" type=\"v\" name=\"ping_invokable\" />\n"
56 " <arg direction=\"out\" type=\"v\" name=\"ping_invokable\" />\n"
57 " </method>\n"
58 " <method name=\"ping\" >\n"
59 " <arg direction=\"in\" type=\"v\" name=\"ping1\" />\n"
60 " <arg direction=\"in\" type=\"v\" name=\"ping2\" />\n"
61 " <arg direction=\"out\" type=\"v\" name=\"pong1\" />\n"
62 " <arg direction=\"out\" type=\"v\" name=\"pong2\" />\n"
63 " </method>\n"
64 " <method name=\"ping_invokable\" >\n"
65 " <arg direction=\"in\" type=\"v\" name=\"ping1_invokable\" />\n"
66 " <arg direction=\"in\" type=\"v\" name=\"ping2_invokable\" />\n"
67 " <arg direction=\"out\" type=\"v\" name=\"pong1_invokable\" />\n"
68 " <arg direction=\"out\" type=\"v\" name=\"pong2_invokable\" />\n"
69 " </method>\n"
70 " <method name=\"ping\" >\n"
71 " <arg direction=\"in\" type=\"ai\" name=\"ping\" />\n"
72 " <arg direction=\"out\" type=\"ai\" name=\"ping\" />\n"
73 " <annotation name=\"org.qtproject.QtDBus.QtTypeName.In0\" value=\"QList&lt;int&gt;\"/>\n"
74 " <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"QList&lt;int&gt;\"/>\n"
75 " </method>\n"
76 " <method name=\"ping_invokable\" >\n"
77 " <arg direction=\"in\" type=\"ai\" name=\"ping_invokable\" />\n"
78 " <arg direction=\"out\" type=\"ai\" name=\"ping_invokable\" />\n"
79 " <annotation name=\"org.qtproject.QtDBus.QtTypeName.In0\" value=\"QList&lt;int&gt;\"/>\n"
80 " <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"QList&lt;int&gt;\"/>\n"
81 " </method>\n"
82 " </interface>\n"
83  "")
84  Q_PROPERTY(int prop1 READ prop1 WRITE setProp1)
85  Q_PROPERTY(QList<int> complexProp READ complexProp WRITE setComplexProp)
86 
87 public:
88  static int callCount;
89  static QVariantList callArgs;
90  MyObject()
91  {
92  QObject *subObject = new QObject(this);
93  subObject->setObjectName("subObject");
94  }
95 
96  int m_prop1;
97  int prop1() const
98  {
99  ++callCount;
100  return m_prop1;
101  }
102  void setProp1(int value)
103  {
104  ++callCount;
105  m_prop1 = value;
106  }
107 
108  QList<int> m_complexProp;
109  QList<int> complexProp() const
110  {
111  ++callCount;
112  return m_complexProp;
113  }
114  void setComplexProp(const QList<int> &value)
115  {
116  ++callCount;
117  m_complexProp = value;
118  }
119 
120  Q_INVOKABLE void ping_invokable(QDBusMessage msg)
121  {
123  ++callCount;
124  callArgs = msg.arguments();
125 
126  msg.setDelayedReply(true);
127  if (!QDBusContext::connection().send(msg.createReply(callArgs)))
128  exit(1);
129  }
130 
131 public slots:
132 
133  void ping(QDBusMessage msg)
134  {
136  ++callCount;
137  callArgs = msg.arguments();
138 
139  msg.setDelayedReply(true);
140  if (!QDBusContext::connection().send(msg.createReply(callArgs)))
141  exit(1);
142  }
143 };
144 
145 #endif // INTERFACE_H
small capitals from c petite p scientific i
[1]
Definition: afcover.h:80
const char msg[]
Definition: arch.cpp:46
#define value
[5]
[0]
Definition: myobject.h:58
void ping(QDBusMessage msg)
Definition: myobject.h:133
void method(const QDBusMessage &msg)
The QDBusContext class allows slots to determine the D-Bus context of the calls.
Definition: qdbuscontext.h:57
bool calledFromDBus() const
QDBusConnection connection() const
The QDBusMessage class represents one message sent or received over the D-Bus bus.
Definition: qdbusmessage.h:58
Definition: qlist.h:108
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
Q_INVOKABLE QObject(QObject *parent=nullptr)
Definition: qobject.cpp:913
QVariant property(const char *name) const
Definition: qobject.cpp:4118
void setObjectName(const QString &name)
Definition: qobject.cpp:1261
auto signal
direction
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char * interface
EGLOutputLayerEXT EGLint EGLAttrib value
GLenum type
Definition: qopengl.h:270
GLsizei const GLfloat * v
[13]
GLenum access
GLuint name
GLfloat n
GLuint in
Definition: qopenglext.h:8870
GLdouble s
[6]
Definition: qopenglext.h:235
#define Q_ASSERT(cond)
Definition: qrandom.cpp:84
SSL_CTX int(*) void arg)
#define Q_PROPERTY(...)
Definition: qtmetamacros.h:92
#define Q_OBJECT
Definition: qtmetamacros.h:158
#define Q_CLASSINFO(name, value)
Definition: qtmetamacros.h:88
#define Q_INVOKABLE
Definition: qtmetamacros.h:112
#define slots
Definition: qtmetamacros.h:76
QTextStream out(stdout)
[7]