Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
src_qdbus_qdbusabstractinterface.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 <QDBusMessage>
6#include <QDBusReply>
7#include <QDBusInterface>
8
9using namespace Qt::StringLiterals;
10
12{
14
15public:
17 : QObject(parent) {
18 interface = new QDBusInterface("org.example.Interface", "/Example/Methods");
19 }
20
23 void asyncCall();
24 QString retrieveValue() { return QString(); }
25
26public slots:
28
29private:
30 QDBusInterface *interface;
31};
32
33void Abstract_DBus_Interface::interfaceMain()
34{
35//! [0]
36QString value = retrieveValue();
37QDBusMessage reply;
38
39QDBusReply<int> api = interface->call("GetAPIVersion"_L1);
40if (api >= 14)
41 reply = interface->call("ProcessWorkUnicode"_L1, value);
42else
43 reply = interface->call("ProcessWork"_L1, "UTF-8"_L1, value.toUtf8());
44//! [0]
45}
46
48{
49//! [1]
50QDBusPendingCall pcall = interface->asyncCall("GetAPIVersion"_L1);
51auto watcher = new QDBusPendingCallWatcher(pcall, this);
52
53QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this,
54 [&](QDBusPendingCallWatcher *w) {
55 QString value = retrieveValue();
56 QDBusPendingReply<int> reply(*w);
57 QDBusPendingCall pcall;
58 if (reply.argumentAt<0>() >= 14)
59 pcall = interface->asyncCall("ProcessWorkUnicode"_L1, value);
60 else
61 pcall = interface->asyncCall("ProcessWork"_L1, "UTF-8"_L1, value.toUtf8());
62
63 w = new QDBusPendingCallWatcher(pcall);
64 QObject::connect(w, &QDBusPendingCallWatcher::finished, this,
65 &Abstract_DBus_Interface::callFinishedSlot);
66});
67//! [1]
68}