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:
parent
9908c7473b
commit
0b5b3fcf1a
26
src/main.cpp
26
src/main.cpp
|
@ -53,6 +53,20 @@ static QList<QByteArray>* logBuffer =
|
||||||
QMutex* logBufferMutex = new QMutex();
|
QMutex* logBufferMutex = new QMutex();
|
||||||
#endif
|
#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)
|
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)
|
// 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")
|
else if (eventType == "save")
|
||||||
handleToxSave(firstParam.toUtf8());
|
handleToxSave(firstParam.toUtf8());
|
||||||
|
|
||||||
|
QObject::connect(a, &QApplication::aboutToQuit, cleanup);
|
||||||
|
|
||||||
// Run (unless we already quit before starting!)
|
// Run (unless we already quit before starting!)
|
||||||
int errorcode = 0;
|
int errorcode = 0;
|
||||||
if (nexus.isRunning())
|
if (nexus.isRunning())
|
||||||
errorcode = a->exec();
|
errorcode = a->exec();
|
||||||
|
|
||||||
Nexus::destroyInstance();
|
qDebug() << "Exit with status" << errorcode;
|
||||||
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
|
|
||||||
|
|
||||||
delete a;
|
delete a;
|
||||||
return errorcode;
|
return errorcode;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user