blob: 04f707dba8a13420f6adc3d8a102be928a7f8994 (
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
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QDBusPendingCall>
#include <QDBusInterface>
#include <QDBusPendingReply>
class DBus_PendingReply_Interface : public QObject
{
Q_OBJECT
public:
DBus_PendingReply_Interface(QObject *parent = nullptr)
: QObject(parent) {
iface = new QDBusInterface("org.example.Interface", "/Example/Methods");
}
~DBus_PendingReply_Interface() { delete iface; }
void callInterfaceMainR();
void PendingReplyString();
void PendingReplyBool();
void showErrorD(QDBusError);
void showSuccess(QVariant);
void showFailure(QVariant);
void useValue(QDBusPendingReplyTypes::Select<0, QString, void, void, void, void, void, void, void>::Type);
public slots:
private:
QDBusInterface *iface;
};
void DBus_PendingReply_Interface::PendingReplyString()
{
//! [0]
QDBusPendingReply<QString> reply = iface->asyncCall("RemoteMethod");
reply.waitForFinished();
if (reply.isError())
// call failed. Show an error condition.
showErrorD(reply.error());
else
// use the returned value
useValue(reply.value());
//! [0]
}
void DBus_PendingReply_Interface::PendingReplyBool()
{
//! [2]
QDBusPendingReply<bool, QString> reply = iface->asyncCall("RemoteMethod");
reply.waitForFinished();
if (!reply.isError()) {
if (reply.argumentAt<0>())
showSuccess(reply.argumentAt<1>());
else
showFailure(reply.argumentAt<1>());
}
//! [2]
}
|