Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(main): Use correct way to handle application quit
Browse files Browse the repository at this point in the history
Handle apllication aboutToQuit signal
  • Loading branch information
Diadlo committed Jun 22, 2017
1 parent 9908c74 commit 0b5b3fc
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

0 comments on commit 0b5b3fc

Please sign in to comment.