1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

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

Handle apllication aboutToQuit signal
This commit is contained in:
Diadlo 2017-06-18 14:35:31 +03:00
parent 9908c7473b
commit 0b5b3fcf1a
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727

View File

@ -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[])
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;
}