Fix restart behavior:

- fix crash.
- exit on last window closed.
- add return staus code for later use.
This commit is contained in:
Julien Wadel 2023-11-29 10:14:50 +01:00
parent 1938ae65e0
commit bdf1d197ec
5 changed files with 17 additions and 6 deletions

View file

@ -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();

View file

@ -76,6 +76,8 @@ public:
QQmlApplicationEngine *mEngine = nullptr;
bool notify(QObject *receiver, QEvent *event);
enum class StatusCode { gRestartCode = 1000, gDeleteDataCode = 1001 };
private:
void createCommandParser();

View file

@ -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;
}
}
// -----------------------------------------------------------------------------

View file

@ -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;
}

View file

@ -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;
}