Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. qDebug instant output?
Forum Updated to NodeBB v4.3 + New Features

qDebug instant output?

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #1

    It seems that when I send output to qDebug, eg:

        qDebug() << __FILE__ << __LINE__ 
                 << strGetNodeName() << strGetAttribute(clsXMLnode::mscszAttrID);
    

    When I single step this in the debugger, I do not see the output in the Application Output, sometimes not till quite a bit later.

    Is there anything to explain this or is this the way its supposed to work? If it is designed behaviour then is there a way to change it to make it output instantly?

    Kind Regards,
    Sy

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #6

      @SPlatten said in qDebug instant output?:

      any guidance on how to achieve this?

      So hard to google for 'qt messagehandler'?
      https://doc.qt.io/qt-5/qtglobal.html#qInstallMessageHandler

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Since qDebug() is using stdio for it's output the os and std specific io buffering is taking effect. Don't know why it is that important for debug output though.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        0
        • SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by
          #3

          @Christian-Ehrlicher , its important for me as I want to see the debug output in order to debug the application, the fact that it doesn't appear when I want it to is a problem.

          Kind Regards,
          Sy

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #4

            Then implement your own qt message handler and make sure your io is not buffered.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            1
            • SPlattenS Offline
              SPlattenS Offline
              SPlatten
              wrote on last edited by
              #5

              @Christian-Ehrlicher , thank you, any guidance on how to achieve this?

              Kind Regards,
              Sy

              1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @SPlatten said in qDebug instant output?:

                any guidance on how to achieve this?

                So hard to google for 'qt messagehandler'?
                https://doc.qt.io/qt-5/qtglobal.html#qInstallMessageHandler

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                3
                • SPlattenS Offline
                  SPlattenS Offline
                  SPlatten
                  wrote on last edited by
                  #7

                  @Christian-Ehrlicher , Thank you, my brain is fried atm.

                  Kind Regards,
                  Sy

                  1 Reply Last reply
                  1
                  • hskoglundH Offline
                    hskoglundH Offline
                    hskoglund
                    wrote on last edited by hskoglund
                    #8

                    Hi, just wanted to add, if you're implementing your message handler exactly like that example in https://doc.qt.io/qt-5/qtglobal.html#qInstallMessageHandler
                    you'll find it will work nicely for qDebug() outputs on Linux and MacOS.

                    On Windows however it will still suffer from the same delay (buffering).
                    It's easy to fix though, just add a fflush(stderr) at the end, like this:

                       ...
                        case QtFatalMsg:
                            fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
                            break;
                        }
                    
                        fflush(stderr);
                    }
                    

                    In my message handler I just leave it in also for MacOS and Linux (it's harmless anyway).

                    Edit: forgot to say: you only need that fflush(stderr); if you're on MinGW, if you're using MSVC 2019 you are more lucky, no fflush() needed (tested with Qt version 5.15.0)

                    1 Reply Last reply
                    2
                    • Christian EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #9

                      @hskoglund said in qDebug instant output?:

                      no fflush() needed

                      I would doubt this. Only with fflush() you can be sure. Everything else does not flush the internal buffer which may work in 99% of all times.

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      1 Reply Last reply
                      2
                      • hskoglundH Offline
                        hskoglundH Offline
                        hskoglund
                        wrote on last edited by
                        #10

                        Yeah, agree. Even though I tested on 5.15.0 and only the combination of Windows and MinGW exhibited that buffering delay, it's better to have it there.

                        Question is then, why does not the example at https://doc.qt.io/qt-5/qtglobal.html#qInstallMessageHandler contain a fflush()?

                        1 Reply Last reply
                        2
                        • SPlattenS Offline
                          SPlattenS Offline
                          SPlatten
                          wrote on last edited by
                          #11

                          I did add a fflush to the function, just to be sure and it all seems to work fine.

                          Kind Regards,
                          Sy

                          1 Reply Last reply
                          1

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved