diff --git a/Linphone/core/App.cpp b/Linphone/core/App.cpp index 11e1e1527..a65712945 100644 --- a/Linphone/core/App.cpp +++ b/Linphone/core/App.cpp @@ -86,6 +86,7 @@ void App::init() { qDebug() << "[App] Starting Thread"; mLinphoneThread->start(); } + setQuitOnLastWindowClosed(true); // TODO: use settings to set it // QML mEngine = new QQmlApplicationEngine(this); @@ -148,6 +149,10 @@ void App::initCppInterfaces() { void App::clean() { // Wait 500ms to let time for log te be stored. + delete mNotifier; + mNotifier = nullptr; + delete mEngine; + mEngine = nullptr; mLinphoneThread->wait(250); qApp->processEvents(QEventLoop::AllEvents, 250); mLinphoneThread->exit(); diff --git a/Linphone/core/App.hpp b/Linphone/core/App.hpp index 0951e6bbb..afd9f6f4b 100644 --- a/Linphone/core/App.hpp +++ b/Linphone/core/App.hpp @@ -76,6 +76,8 @@ public: QQmlApplicationEngine *mEngine = nullptr; bool notify(QObject *receiver, QEvent *event); + enum class StatusCode { gRestartCode = 1000, gDeleteDataCode = 1001 }; + private: void createCommandParser(); diff --git a/Linphone/core/notifier/Notifier.cpp b/Linphone/core/notifier/Notifier.cpp index cf6363ae0..538a09ef1 100644 --- a/Linphone/core/notifier/Notifier.cpp +++ b/Linphone/core/notifier/Notifier.cpp @@ -118,9 +118,11 @@ Notifier::~Notifier() { delete mMutex; const int nComponents = Notifications.size(); - for (int i = 0; i < nComponents; ++i) - mComponents[i]->deleteLater(); - delete[] mComponents; + if (mComponents) { + for (int i = 0; i < nComponents; ++i) + if (mComponents[i]) mComponents[i]->deleteLater(); + delete[] mComponents; + } } // ----------------------------------------------------------------------------- diff --git a/Linphone/main.cpp b/Linphone/main.cpp index fcd63346a..c10cd7432 100644 --- a/Linphone/main.cpp +++ b/Linphone/main.cpp @@ -46,9 +46,10 @@ int main(int argc, char *argv[]) { #endif int result = 0; - while (result >= 0) { + do { result = app.exec(); - } + } while (result == (int)App::StatusCode::gRestartCode); + qWarning() << "[Main] Exiting app with the code : " << result; app.clean(); return result; } diff --git a/Linphone/tool/thread/Thread.cpp b/Linphone/tool/thread/Thread.cpp index af126279d..2daca432d 100644 --- a/Linphone/tool/thread/Thread.cpp +++ b/Linphone/tool/thread/Thread.cpp @@ -44,7 +44,8 @@ bool Thread::mustBeInLinphoneThread(const QString &context) { } bool Thread::mustBeInMainThread(const QString &context) { - bool isMainThread = QThread::currentThread() == App::getInstance()->thread(); + if (!qApp) return true; + bool isMainThread = QThread::currentThread() == qApp->thread(); if (!isMainThread) qCritical() << "[Thread] Not processing in Main thread from " << context; return isMainThread; }