Delay creation of QEventLoop object until after QCoreApplication starts
Fixes: QEventLoop: Cannot be used without QApplication
This commit is contained in:
parent
67e943713b
commit
a7b640da4c
|
@ -62,6 +62,7 @@ ActionReply ExternalCommandHelper::init(const QVariantMap& args)
|
||||||
|
|
||||||
m_publicKey = QCA::PublicKey::fromDER(args[QStringLiteral("pubkey")].toByteArray());
|
m_publicKey = QCA::PublicKey::fromDER(args[QStringLiteral("pubkey")].toByteArray());
|
||||||
|
|
||||||
|
m_loop = std::make_unique<QEventLoop>();
|
||||||
HelperSupport::progressStep(QVariantMap());
|
HelperSupport::progressStep(QVariantMap());
|
||||||
auto timeout = [this] () {
|
auto timeout = [this] () {
|
||||||
QDBusInterface iface(QStringLiteral("org.kde.kpmcore.applicationinterface"),
|
QDBusInterface iface(QStringLiteral("org.kde.kpmcore.applicationinterface"),
|
||||||
|
@ -74,7 +75,7 @@ ActionReply ExternalCommandHelper::init(const QVariantMap& args)
|
||||||
auto exitLoop = [&] (QDBusPendingCallWatcher *watcher) {
|
auto exitLoop = [&] (QDBusPendingCallWatcher *watcher) {
|
||||||
if (watcher->isError()) {
|
if (watcher->isError()) {
|
||||||
qWarning() << watcher->error();
|
qWarning() << watcher->error();
|
||||||
m_loop.exit();
|
m_loop->exit();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
connect(watcher, &QDBusPendingCallWatcher::finished, exitLoop);
|
connect(watcher, &QDBusPendingCallWatcher::finished, exitLoop);
|
||||||
|
@ -83,7 +84,7 @@ ActionReply ExternalCommandHelper::init(const QVariantMap& args)
|
||||||
QTimer *timer = new QTimer(this);
|
QTimer *timer = new QTimer(this);
|
||||||
connect(timer, &QTimer::timeout, this, timeout);
|
connect(timer, &QTimer::timeout, this, timeout);
|
||||||
timer->start(5000); // 5 seconds
|
timer->start(5000); // 5 seconds
|
||||||
m_loop.exec();
|
m_loop->exec();
|
||||||
reply.addData(QStringLiteral("success"), true);
|
reply.addData(QStringLiteral("success"), true);
|
||||||
|
|
||||||
return reply;
|
return reply;
|
||||||
|
@ -313,7 +314,7 @@ void ExternalCommandHelper::exit(const QByteArray& signature, const quint64 nonc
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_loop.exit();
|
m_loop->exit();
|
||||||
|
|
||||||
QDBusConnection::systemBus().unregisterObject(QStringLiteral("/Helper"));
|
QDBusConnection::systemBus().unregisterObject(QStringLiteral("/Helper"));
|
||||||
QDBusConnection::systemBus().unregisterService(QStringLiteral("org.kde.kpmcore.helperinterface"));
|
QDBusConnection::systemBus().unregisterService(QStringLiteral("org.kde.kpmcore.helperinterface"));
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#ifndef KPMCORE_EXTERNALCOMMANDHELPER_H
|
#ifndef KPMCORE_EXTERNALCOMMANDHELPER_H
|
||||||
#define KPMCORE_EXTERNALCOMMANDHELPER_H
|
#define KPMCORE_EXTERNALCOMMANDHELPER_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
#include <KAuth>
|
#include <KAuth>
|
||||||
|
@ -54,7 +55,7 @@ public Q_SLOTS:
|
||||||
private:
|
private:
|
||||||
void onReadOutput();
|
void onReadOutput();
|
||||||
|
|
||||||
QEventLoop m_loop;
|
std::unique_ptr<QEventLoop> m_loop;
|
||||||
QCA::Initializer initializer;
|
QCA::Initializer initializer;
|
||||||
QCA::PublicKey m_publicKey;
|
QCA::PublicKey m_publicKey;
|
||||||
QRandomGenerator64 m_Generator;
|
QRandomGenerator64 m_Generator;
|
||||||
|
|
Loading…
Reference in New Issue