Browse Source

fix(main): Use correct way to handle application quit

Handle apllication aboutToQuit signal
reviewable/pr4476/r1
Diadlo 8 years ago
parent
commit
0b5b3fcf1a
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
  1. 26
      src/main.cpp

26
src/main.cpp

@ -53,6 +53,20 @@ static QList<QByteArray>* logBuffer = @@ -53,6 +53,20 @@ static QList<QByteArray>* logBuffer =
QMutex* logBufferMutex = new QMutex();
#endif
void cleanup()
{
Nexus::destroyInstance();
CameraSource::destroyInstance();
Settings::destroyInstance();
qDebug() << "Cleanup success";
#ifdef LOG_TO_FILE
FILE* f = logFileFile.load();
fclose(f);
logFileFile.store(nullptr); // atomically disable logging to file
#endif
}
void logMessageHandler(QtMsgType type, const QMessageLogContext& ctxt, const QString& msg)
{
// Silence qWarning spam due to bug in QTextBrowser (trying to open a file for base64 images)
@ -297,22 +311,14 @@ int main(int argc, char* argv[]) @@ -297,22 +311,14 @@ int main(int argc, char* argv[])
else if (eventType == "save")
handleToxSave(firstParam.toUtf8());
QObject::connect(a, &QApplication::aboutToQuit, cleanup);
// Run (unless we already quit before starting!)
int errorcode = 0;
if (nexus.isRunning())
errorcode = a->exec();
Nexus::destroyInstance();
CameraSource::destroyInstance();
Settings::destroyInstance();
qDebug() << "Clean exit with status" << errorcode;
#ifdef LOG_TO_FILE
logFileFile.store(nullptr); // atomically disable logging to file
fclose(mainLogFilePtr);
#endif
qDebug() << "Exit with status" << errorcode;
delete a;
return errorcode;
}

Loading…
Cancel
Save