Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ricardodovalle/5915633 to your computer and use it in GitHub Desktop.
Save ricardodovalle/5915633 to your computer and use it in GitHub Desktop.
#include <QApplication>
#include <QDebug>
void messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
QByteArray localMsg = msg.toUtf8();
switch (type) {
case QtDebugMsg:
fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
case QtWarningMsg:
fprintf(stderr, "Warni: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
case QtCriticalMsg:
fprintf(stderr, "Criti: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
case QtFatalMsg:
fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
abort();
}
fflush(stderr);
}
int main(int argc, char *argv[])
{
qInstallMessageHandler(messageOutput);
QApplication app(argc, argv);
qDebug() << "Teste";
qWarning() << "Teste";
qCritical() << "Teste";
qFatal("Teste");
return app.exec();
}
@balmyBanzai
Copy link

(Qt 5.5.1 on Windows 10) - This code example never finishes, and does not write to the console

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment