From c1d8d6a52d24d24a2bb7bad03ebc41f6b4d8970f Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Thu, 25 Jan 2018 15:14:09 +0100 Subject: [PATCH] Properly run Qt event loop Check RsControlModule.processShouldExit() via a lazy timer this should guarantee QCoreApplication enough autonomy to gracefully handle any event specially stop --- retroshare-android-service/src/service.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/retroshare-android-service/src/service.cpp b/retroshare-android-service/src/service.cpp index 6729768cc..a2ee0867a 100644 --- a/retroshare-android-service/src/service.cpp +++ b/retroshare-android-service/src/service.cpp @@ -1,6 +1,6 @@ /* * RetroShare Android Service - * Copyright (C) 2016-2017 Gioacchino Mazzurco + * Copyright (C) 2016-2018 Gioacchino Mazzurco * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -18,8 +18,8 @@ #include #include -#include #include +#include #ifdef __ANDROID__ # include "util/androiddebug.h" @@ -52,16 +52,10 @@ int main(int argc, char *argv[]) ApiServerLocal apiServerLocal(&api, sockPath); (void) apiServerLocal; - while (!ctrl_mod.processShouldExit()) - { - app.processEvents(); - usleep(20000); - } - - /* Since QCoreApplication::quit() is a no-op until the event loop has been - * started, we need to defer the call until it starts. Thus, we queue a - * deferred method call to quit() */ - QMetaObject::invokeMethod(&app, "quit", Qt::QueuedConnection); + QTimer shouldExitTimer; + QObject::connect( &shouldExitTimer, &QTimer::timeout, [&](){ + if(ctrl_mod.processShouldExit()) app.quit(); }); + shouldExitTimer.start(); return app.exec(); }