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
As Frank Osterfeld mentioned in his comment:
On windows, qDebug() uses the debug channel, not stderr.
After delving into the QDebug code and QMessageLogger I've found my answer. The handy WinAPI function OutputDebugString.
Usage (Modified from peppe's):
#include
#include
#include
#include
#include
#include
void MyMessageOutput(QtMsgType Type, const QMessageLogContext& Context, const QString &Message)
{
OutputDebugString(reinterpret_cast(Message.utf16()));
}
int main(int argc, char **argv)
{
// A GUI application
QApplication app(argc, argv);
// Custom handler
qInstallMessageHandler(myMessageOutput);
qDebug() << "Printed in the console using my message handler in a windows GUI application";
// Default handler
qInstallMessageHandler(0);
qDebug() << "Also printed in the console!";
// Show GUI here
//MainForm *MF = new MainForm();
//MF->show();
return app.exec();
}