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

Fix crash on exit

Static destructors were being called in an inconvenient order, replace that with a pointer and check for nullity
This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-11-02 08:55:11 +01:00
parent fd67a375ea
commit d90ce6b45f
No known key found for this signature in database
GPG Key ID: 7E086DD661263264

View File

@ -25,13 +25,16 @@
#ifdef LOG_TO_FILE #ifdef LOG_TO_FILE
static QtMessageHandler dflt; static QtMessageHandler dflt;
static QTextStream logFile; static QTextStream* logFile {nullptr};
void myMessageHandler(QtMsgType type, const QMessageLogContext& ctxt, const QString& msg) void myMessageHandler(QtMsgType type, const QMessageLogContext& ctxt, const QString& msg)
{ {
if (!logFile)
return;
dflt(type, ctxt, msg); dflt(type, ctxt, msg);
logFile << QTime::currentTime().toString("HH:mm:ss' '") << msg << '\n'; *logFile << QTime::currentTime().toString("HH:mm:ss' '") << msg << '\n';
logFile.flush(); logFile->flush();
} }
#endif #endif
@ -42,12 +45,13 @@ int main(int argc, char *argv[])
a.setOrganizationName("Tox"); a.setOrganizationName("Tox");
#ifdef LOG_TO_FILE #ifdef LOG_TO_FILE
logFile = new QTextStream;
dflt = qInstallMessageHandler(nullptr); dflt = qInstallMessageHandler(nullptr);
QFile logfile(QDir(Settings::getSettingsDirPath()).filePath("qtox.log")); QFile logfile(QDir(Settings::getSettingsDirPath()).filePath("qtox.log"));
logfile.open(QIODevice::Append); logfile.open(QIODevice::Append);
logFile.setDevice(&logfile); logFile->setDevice(&logfile);
logFile << QDateTime::currentDateTime().toString("yyyy-dd-MM HH:mm:ss' file logger starting\n'"); *logFile << QDateTime::currentDateTime().toString("yyyy-dd-MM HH:mm:ss' file logger starting\n'");
qInstallMessageHandler(myMessageHandler); qInstallMessageHandler(myMessageHandler);
#endif #endif
@ -66,6 +70,10 @@ int main(int argc, char *argv[])
int errorcode = a.exec(); int errorcode = a.exec();
delete w; delete w;
#ifdef LOG_TO_FILE
delete logFile;
logFile = nullptr;
#endif
return errorcode; return errorcode;
} }