After searching around for a reason that qDebug() statements work fine with Qt\'s standard message handler but fail when I switch to my own, I\'m appealing here to see if an
I can't reproduce your issue: this works correctly for me.
#include
#include
#include
#include
#include
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
QByteArray localMsg = msg.toLocal8Bit();
fprintf(stderr, "MESSAGE (%s:%u %s): %s\n", context.file, context.line, context.function, localMsg.constData());
fflush(stderr);
}
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
qInstallMessageHandler(myMessageOutput);
qDebug() << "Printed in the console";
qInstallMessageHandler(0);
qDebug() << "Also printed in the console";
return app.exec();
}