PDA

View Full Version : qInstallMessageHandler, Messages only at once when i close EXE? not during runtime



HappyCoder
8th March 2016, 13:17
Hello,

up to now i used qDebug() to get messages into the output of QtCreator.
The messages are printed into the output window of QtCreator when they are called.

I created a MessageHandler like it is here: http://doc.qt.io/qt-5/qtglobal.html#qInstallMessageHandler

When i now start my application i don't have ANY messages in my console output
in QtCreator during run time. When i close my EXE all messages are printed out
at once.

What's going wrong here? It seems that all messages are "collected" somewhere
and when the EXE will be closed all printed to the console in QtCreator.
Is it normal when using qInstallMessageHandler?

Windows 7, Qt 5.5.1 and QtCreator 3.5.1

Thx

anda_skoa
8th March 2016, 13:35
Looks like you forgot to post the code of your message handler :-)

Cheers,
_

HappyCoder
8th March 2016, 14:08
Looks like you forgot to post the code of your message handler :-)
_

It is like in the URL, nothing changed:



void MyMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
QByteArray localMsg = msg.toLocal8Bit();
QString messageType;
switch (type)
{
case QtDebugMsg:
fprintf(stderr, "DBG: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
case QtInfoMsg:
fprintf(stderr, "INF: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
case QtWarningMsg:
fprintf(stderr, "WRN: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
case QtCriticalMsg:
fprintf(stderr, "CRT: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
case QtFatalMsg:
fprintf(stderr, "FAT: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
abort();
}
}

anda_skoa
8th March 2016, 14:42
Usually stderr is not buffered, but since this is Windows, who knows.

Have you tried fflush(stderr) at the end?

Cheers,
_

HappyCoder
8th March 2016, 14:56
Have you tried fflush(stderr) at the end?
_

That's it! Now i got the messages at runtime and not all at once when i close the application.

gurpreettamber
30th June 2017, 13:43
Yes!! It worked. Logs are now appearing at run-time. Thanks.