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
|
// Copyright (C) 2025 Intel Corporation.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtCore/QTimer>
#include <QtCore/QCoreApplication>
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusMessage>
#include <stdio.h>
using namespace Qt::StringLiterals;
using namespace std::chrono_literals;
static QString myInterface()
{
return u"local.qdbusdelayeddeliveryreenablehelper"_s;
}
static void makeSynchronousCall(QDBusConnection &conn)
{
QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.DBus", "/",
"org.freedesktop.DBus.Peer", "Ping");
conn.call(msg);
}
static void emitSignal(QDBusConnection &conn)
{
QDBusMessage msg = QDBusMessage::createSignal("/", myInterface(), "quit");
conn.send(msg);
}
int main(int argc, char **argv)
{
// Open a connection to the bus *before* QCoreApplication exists;
// this will put the connection in delayed delivery mode
QDBusConnection session = QDBusConnection::sessionBus();
if (!session.isConnected()) {
fprintf(stderr, "Session bus did not connect!");
return 1;
}
makeSynchronousCall(session);
QCoreApplication app(argc, argv);
QTimer::singleShot(15s, qApp, [] {
fprintf(stderr, "Did not receive signal.\n");
qApp->exit(1);
});
// connect a remote, wildcard signal to qApp->quit()
session.connect(QString(), QString(), myInterface(), "quit", &app, SLOT(quit()));
// send ourselves the signal to quit, via D-Bus
emitSignal(session);
return app.exec();
}
|