Hi
I realize the default behavior of qFatal() is to terminate an application. However the documentation suggests if I install a message handler it wont. But it is. How can I stop qFatal() from killing my application?
To clarify I have the following code. I actually do want to quit on qFatal() but I want to do clean up too. In this code the qApp->quit() slot is never executed because its asyncronous and something is killing my app before the event loop has a chance to pick it up. (omitting the arbitrary bit of code somewhere that actually calls a `qFatal()` because its not important):
#include <QtGlobal>
#include <QApplication>
#include <unistd.h>
#include <stdio.h>
void LogMsgHandler(QtMsgType type, const char *msg)
{
switch (type) {
#ifndef QT_NO_DEBUG_OUTPUT
case QtDebugMsg:
printf("DEBUG: %s\n", msg);
break;
#endif
case QtWarningMsg:
printf("WARNING: %s\n", msg);
break;
case QtCriticalMsg:
printf("CRITICAL: %s\n", msg);
break;
case QtFatalMsg:
printf("FATAL: %s\n", msg);
qApp->quit(); // Does not generate aboutToQuit(). Does not exit event loop.
}
printf("Exiting handler\n");
}
int main(int argc, char *argv[])
{
qInstallMsgHandler(LogMsgHandler);
Controller controller;
app.exec();
printf("Never get here. Because something kill my app.\n");
}
#include <QtGlobal>
#include <QApplication>
#include <unistd.h>
#include <stdio.h>
void LogMsgHandler(QtMsgType type, const char *msg)
{
switch (type) {
#ifndef QT_NO_DEBUG_OUTPUT
case QtDebugMsg:
printf("DEBUG: %s\n", msg);
break;
#endif
case QtWarningMsg:
printf("WARNING: %s\n", msg);
break;
case QtCriticalMsg:
printf("CRITICAL: %s\n", msg);
break;
case QtFatalMsg:
printf("FATAL: %s\n", msg);
qApp->quit(); // Does not generate aboutToQuit(). Does not exit event loop.
}
printf("Exiting handler\n");
}
int main(int argc, char *argv[])
{
qInstallMsgHandler(LogMsgHandler);
QCoreApplication app(argc, argv);
Controller controller;
app.exec();
printf("Never get here. Because something kill my app.\n");
}
To copy to clipboard, switch view to plain text mode
Thanks.
Bookmarks