Debian Codegraph @

src/dbus/doc/snippets/code/src_qdbus_qdbusreply.cpp

raw
1 // Copyright (C) 2016 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3 #include <QDBusPendingCall>
4 #include <QDBusInterface>
5 #include <QDBusPendingReply>
6 #include <QDBusReply>
7
8 class DBus_Process_String_Interface : public QObject
9 {
10 Q_OBJECT
11
12 public:
13 DBus_Process_String_Interface(QObject *parent = nullptr)
14 : QObject(parent) {
15 interface = new QDBusInterface("org.example.Interface", "/Example/Methods");
16 }
17
18 ~DBus_Process_String_Interface() { delete interface; }
19 void QDBus_reply();
20 void useValue(QVariant);
21 void showError(const QDBusError&);
22 public slots:
23
24 private:
25 QDBusInterface *interface;
26 };
27 void DBus_Process_String_Interface::QDBus_reply()
28 {
29 //! [0]
30 QDBusReply<QString> reply = interface->call("RemoteMethod");
31 if (reply.isValid())
32 // use the returned value
33 useValue(reply.value());
34 else
35 // call failed. Show an error condition.
36 showError(reply.error());
37 //! [0]
38
39
40 //! [1]
41 reply = interface->call("RemoteMethod");
42 //! [1]
43 }