From 0b1a6427ef688085d8f98ba3742d1aebdcabeebb Mon Sep 17 00:00:00 2001 From: Piotr Gawlowicz Date: Wed, 5 Jul 2023 11:50:28 +0200 Subject: [PATCH 1/2] allow for a graceful exit without errors --- src/srsgui++.cpp | 13 +++++++++---- src/srsgui.cpp | 14 +++++++++----- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/srsgui++.cpp b/src/srsgui++.cpp index 5ea107ff..f752e36a 100644 --- a/src/srsgui++.cpp +++ b/src/srsgui++.cpp @@ -4,14 +4,16 @@ #include pthread_t threadxx; +QApplication* appxx; static int sdrgui_initiatedxx=0; void *qt_threadxx(void *arg) { int argc = 1; char* argv[] = { const_cast((char*) arg), NULL }; - QApplication app(argc, argv); - app.exec(); + appxx = new QApplication(argc, argv); + appxx->exec(); + delete appxx; pthread_exit(NULL); } @@ -41,8 +43,11 @@ void sdrgui_exit() { if(sdrgui_initiatedxx) { usleep(100000); - pthread_cancel(threadxx); + if(appxx) { + appxx->quit(); + } + pthread_join(threadxx, NULL); - } + } sdrgui_initiatedxx=0; } diff --git a/src/srsgui.cpp b/src/srsgui.cpp index 51e18a13..025fcb4b 100644 --- a/src/srsgui.cpp +++ b/src/srsgui.cpp @@ -5,14 +5,16 @@ #include pthread_t thread; +QApplication* app; static int sdrgui_initiated=0; void *qt_thread(void *arg) { int argc = 1; char* argv[] = { const_cast((char*) arg), NULL }; - QApplication app(argc, argv); - app.exec(); + app = new QApplication(argc, argv); + app->exec(); + delete app; pthread_exit(NULL); } @@ -43,8 +45,10 @@ void sdrgui_exit() if(sdrgui_initiated) { usleep(100000); - pthread_cancel(thread); - pthread_join(thread, NULL); - } + if (app) { + app->quit(); + } + pthread_join(thread, NULL); + } sdrgui_initiated=0; } From 2c4aa46e88cac09f836acaf66aa4039c1fc2da54 Mon Sep 17 00:00:00 2001 From: Piotr Gawlowicz Date: Wed, 5 Jul 2023 11:50:53 +0200 Subject: [PATCH 2/2] allow for a graceful exit even if the app window was already closed --- src/complexplot/ComplexplotWrapper.cpp | 4 ++++ src/keyvalue/KeyValueWrapper.cpp | 4 ++++ src/realplot/RealplotWrapper.cpp | 4 ++++ src/scatterplot/ScatterplotWrapper.cpp | 4 ++++ src/textedit/TextEditWrapper.cpp | 4 ++++ src/waterfallplot/WaterfallplotWrapper.cpp | 4 ++++ 6 files changed, 24 insertions(+) diff --git a/src/complexplot/ComplexplotWrapper.cpp b/src/complexplot/ComplexplotWrapper.cpp index 652c1b14..9f14bc8d 100755 --- a/src/complexplot/ComplexplotWrapper.cpp +++ b/src/complexplot/ComplexplotWrapper.cpp @@ -42,6 +42,10 @@ ComplexplotWrapper::ComplexplotWrapper() ComplexplotWrapper::~ComplexplotWrapper() { + if(QCoreApplication::instance() == NULL) { + destroyed_ = true; + } + if(destroyed_) emit destroyWidgetSignal(); else diff --git a/src/keyvalue/KeyValueWrapper.cpp b/src/keyvalue/KeyValueWrapper.cpp index 296b6b19..fe916ca6 100644 --- a/src/keyvalue/KeyValueWrapper.cpp +++ b/src/keyvalue/KeyValueWrapper.cpp @@ -39,6 +39,10 @@ KeyValueWrapper::KeyValueWrapper() KeyValueWrapper::~KeyValueWrapper() { + if(QCoreApplication::instance() == NULL) { + destroyed_ = true; + } + if(destroyed_) emit destroyWidgetSignal(); else diff --git a/src/realplot/RealplotWrapper.cpp b/src/realplot/RealplotWrapper.cpp index 773333a5..2d8c3d10 100755 --- a/src/realplot/RealplotWrapper.cpp +++ b/src/realplot/RealplotWrapper.cpp @@ -38,6 +38,10 @@ RealplotWrapper::RealplotWrapper() RealplotWrapper::~RealplotWrapper() { + if(QCoreApplication::instance() == NULL) { + destroyed_ = true; + } + if(destroyed_) emit destroyWidgetSignal(); else diff --git a/src/scatterplot/ScatterplotWrapper.cpp b/src/scatterplot/ScatterplotWrapper.cpp index 861b7d04..0351463a 100755 --- a/src/scatterplot/ScatterplotWrapper.cpp +++ b/src/scatterplot/ScatterplotWrapper.cpp @@ -42,6 +42,10 @@ ScatterplotWrapper::ScatterplotWrapper() ScatterplotWrapper::~ScatterplotWrapper() { + if(QCoreApplication::instance() == NULL) { + destroyed_ = true; + } + if(destroyed_) emit destroyWidgetSignal(); else diff --git a/src/textedit/TextEditWrapper.cpp b/src/textedit/TextEditWrapper.cpp index 42d38d33..db757575 100644 --- a/src/textedit/TextEditWrapper.cpp +++ b/src/textedit/TextEditWrapper.cpp @@ -39,6 +39,10 @@ TextEditWrapper::TextEditWrapper() TextEditWrapper::~TextEditWrapper() { + if(QCoreApplication::instance() == NULL) { + destroyed_ = true; + } + if(destroyed_) emit destroyWidgetSignal(); else diff --git a/src/waterfallplot/WaterfallplotWrapper.cpp b/src/waterfallplot/WaterfallplotWrapper.cpp index 17ad0e2a..8ca20980 100755 --- a/src/waterfallplot/WaterfallplotWrapper.cpp +++ b/src/waterfallplot/WaterfallplotWrapper.cpp @@ -39,6 +39,10 @@ WaterfallplotWrapper::WaterfallplotWrapper(int numDataPoints, int numRows) WaterfallplotWrapper::~WaterfallplotWrapper() { + if(QCoreApplication::instance() == NULL) { + destroyed_ = true; + } + if(destroyed_) emit destroyWidgetSignal(); else