Results 1 to 6 of 6

Thread: qInstallMessageHandler, Messages only at once when i close EXE? not during runtime

  1. #1
    Join Date
    Jul 2015
    Posts
    87
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default qInstallMessageHandler, Messages only at once when i close EXE? not during runtime

    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#...MessageHandler

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qInstallMessageHandler, Messages only at once when i close EXE? not during runtim

    Looks like you forgot to post the code of your message handler :-)

    Cheers,
    _

  3. #3
    Join Date
    Jul 2015
    Posts
    87
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: qInstallMessageHandler, Messages only at once when i close EXE? not during runtim

    Quote Originally Posted by anda_skoa View Post
    Looks like you forgot to post the code of your message handler :-)
    _
    It is like in the URL, nothing changed:

    Qt Code:
    1. void MyMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
    2. {
    3. QByteArray localMsg = msg.toLocal8Bit();
    4. QString messageType;
    5. switch (type)
    6. {
    7. case QtDebugMsg:
    8. fprintf(stderr, "DBG: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
    9. break;
    10. case QtInfoMsg:
    11. fprintf(stderr, "INF: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
    12. break;
    13. case QtWarningMsg:
    14. fprintf(stderr, "WRN: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
    15. break;
    16. case QtCriticalMsg:
    17. fprintf(stderr, "CRT: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
    18. break;
    19. case QtFatalMsg:
    20. fprintf(stderr, "FAT: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
    21. abort();
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by HappyCoder; 8th March 2016 at 14:27.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qInstallMessageHandler, Messages only at once when i close EXE? not during runtim

    Usually stderr is not buffered, but since this is Windows, who knows.

    Have you tried fflush(stderr) at the end?

    Cheers,
    _

  5. #5
    Join Date
    Jul 2015
    Posts
    87
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: qInstallMessageHandler, Messages only at once when i close EXE? not during runtim

    Quote Originally Posted by anda_skoa View Post
    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.

  6. #6
    Join Date
    Jun 2017
    Posts
    1
    Qt products
    Qt5
    Platforms
    MacOS X Windows Android

    Thumbs up Re: qInstallMessageHandler, Messages only at once when i close EXE? not during runtim

    Yes!! It worked. Logs are now appearing at run-time. Thanks.

Similar Threads

  1. binding to qInstallMessageHandler
    By TorAn in forum Qt Programming
    Replies: 4
    Last Post: 21st December 2013, 16:51
  2. Why qInstallMessageHandler not run on console app?
    By patrik08 in forum Qt Programming
    Replies: 0
    Last Post: 20th November 2013, 11:37
  3. Replies: 2
    Last Post: 17th December 2010, 19:01
  4. Replies: 1
    Last Post: 25th September 2010, 08:20
  5. Replies: 3
    Last Post: 16th November 2006, 12:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.