From aa705b0ef5dcba85a914c3cffcf72179c864fd7c Mon Sep 17 00:00:00 2001 From: Gres Date: Mon, 28 Sep 2015 22:17:24 +0300 Subject: [PATCH] More proper app termination. --- Manager.cpp | 6 ++++++ Manager.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/Manager.cpp b/Manager.cpp index 3932fc1..26af69a 100644 --- a/Manager.cpp +++ b/Manager.cpp @@ -40,6 +40,7 @@ Manager::Manager (QObject *parent) : connect (this, SIGNAL (settingsEdited ()), recognizer, SLOT (applySettings ())); QThread *recognizerThread = new QThread (this); + threads_ << recognizerThread; recognizer->moveToThread (recognizerThread); recognizerThread->start (); connect (qApp, SIGNAL (aboutToQuit ()), recognizerThread, SLOT (quit ())); @@ -54,6 +55,7 @@ Manager::Manager (QObject *parent) : connect (this, SIGNAL (settingsEdited ()), translator, SLOT (applySettings ())); QThread *translatorThread = new QThread (this); + threads_ << translatorThread; translator->moveToThread (translatorThread); translatorThread->start (); connect (qApp, SIGNAL (aboutToQuit ()), translatorThread, SLOT (quit ())); @@ -127,6 +129,10 @@ void Manager::applySettings () { } Manager::~Manager () { + foreach (QThread * thread, threads_) { + thread->quit (); + thread->wait (1000000); + } } void Manager::capture () { diff --git a/Manager.h b/Manager.h index d105e69..a27a566 100644 --- a/Manager.h +++ b/Manager.h @@ -56,6 +56,8 @@ class Manager : public QObject { QAction *clipboardAction_; ProcessingItem lastItem_; bool useResultDialog_; + //! Used threads. For proper termination. + QList threads_; }; #endif // MANAGER_H