Delay creation of QEventLoop object until after QCoreApplication starts

Fixes: QEventLoop: Cannot be used without QApplication
This commit is contained in:
Andrius Štikonas 2018-08-03 19:37:24 +01:00
parent 67e943713b
commit a7b640da4c
2 changed files with 6 additions and 4 deletions

View File

@ -62,6 +62,7 @@ ActionReply ExternalCommandHelper::init(const QVariantMap& args)
m_publicKey = QCA::PublicKey::fromDER(args[QStringLiteral("pubkey")].toByteArray());
m_loop = std::make_unique<QEventLoop>();
HelperSupport::progressStep(QVariantMap());
auto timeout = [this] () {
QDBusInterface iface(QStringLiteral("org.kde.kpmcore.applicationinterface"),
@ -74,7 +75,7 @@ ActionReply ExternalCommandHelper::init(const QVariantMap& args)
auto exitLoop = [&] (QDBusPendingCallWatcher *watcher) {
if (watcher->isError()) {
qWarning() << watcher->error();
m_loop.exit();
m_loop->exit();
}
};
connect(watcher, &QDBusPendingCallWatcher::finished, exitLoop);
@ -83,7 +84,7 @@ ActionReply ExternalCommandHelper::init(const QVariantMap& args)
QTimer *timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, timeout);
timer->start(5000); // 5 seconds
m_loop.exec();
m_loop->exec();
reply.addData(QStringLiteral("success"), true);
return reply;
@ -313,7 +314,7 @@ void ExternalCommandHelper::exit(const QByteArray& signature, const quint64 nonc
return;
}
m_loop.exit();
m_loop->exit();
QDBusConnection::systemBus().unregisterObject(QStringLiteral("/Helper"));
QDBusConnection::systemBus().unregisterService(QStringLiteral("org.kde.kpmcore.helperinterface"));

View File

@ -18,6 +18,7 @@
#ifndef KPMCORE_EXTERNALCOMMANDHELPER_H
#define KPMCORE_EXTERNALCOMMANDHELPER_H
#include <memory>
#include <unordered_set>
#include <KAuth>
@ -54,7 +55,7 @@ public Q_SLOTS:
private:
void onReadOutput();
QEventLoop m_loop;
std::unique_ptr<QEventLoop> m_loop;
QCA::Initializer initializer;
QCA::PublicKey m_publicKey;
QRandomGenerator64 m_Generator;