Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. qDebug() , qWarning(), qFatal(), qCritical
Forum Update on Monday, May 27th 2025

qDebug() , qWarning(), qFatal(), qCritical

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 17.9k Views
  • 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.
  • ashajgA Offline
    ashajgA Offline
    ashajg
    wrote on last edited by ashajg
    #1

    hi guys

    I want to do some study on qDebug(), qWarning(), qFatal() and qCritical.
    I went through this document https://doc.qt.io/qt-5/qtglobal.html#qCritical
    What is exact difference in all 4 and how to effectively use them in program?
    I wrote a small code

    code :

    if(c == 100)
       {
           qDebug()<<"Value is "<<c;
           qInfo()<<"INFO VALUE is";
           qCritical()<<"qWarning";
           qFatal("fatal error");
           qDebug()<<"Value is "<<c;
       }
    

    **output:

    Value is 100
    INFO VALUE is
    qwarning
    qCritical
    fatal error**

    so I got to know that qFatal will terminate the program but how I can use qWarning, qCritical or qInfo effectively as i cannot see any difference in logs of qWarning, qCritical , qInfo and qDebug.

    Thanks and Regards
    Ashish

    JonBJ aha_1980A 2 Replies Last reply
    0
    • ashajgA ashajg

      hi guys

      I want to do some study on qDebug(), qWarning(), qFatal() and qCritical.
      I went through this document https://doc.qt.io/qt-5/qtglobal.html#qCritical
      What is exact difference in all 4 and how to effectively use them in program?
      I wrote a small code

      code :

      if(c == 100)
         {
             qDebug()<<"Value is "<<c;
             qInfo()<<"INFO VALUE is";
             qCritical()<<"qWarning";
             qFatal("fatal error");
             qDebug()<<"Value is "<<c;
         }
      

      **output:

      Value is 100
      INFO VALUE is
      qwarning
      qCritical
      fatal error**

      so I got to know that qFatal will terminate the program but how I can use qWarning, qCritical or qInfo effectively as i cannot see any difference in logs of qWarning, qCritical , qInfo and qDebug.

      Thanks and Regards
      Ashish

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @ashajg
      See also https://doc.qt.io/qt-5/debug.html, section Warning and Debugging Messages, which summarises the purpose of each one. If you read, each one has its own behaviour in terms of testing compile-time #defines or runtime environment variables.

      They all do a similar job (by default): output some text, which you can see in e.g. the Qt Creator Console window. They do so via an inbuilt Qt "message handler". You can put your own message handler in via https://doc.qt.io/qt-5/qtglobal.html#qInstallMessageHandler, and have it execute your own logic. In my own code, I test the https://doc.qt.io/qt-5/qtglobal.html#QtMsgType-enum of a message against a "debug level" I read in from an external configuration file and only issue the message for those above a certain level. So I can change the configuration file value to control whether, say, QtInfoMsg messages are or are not output.

      So... pepper your code with the ones appropriate to the situation: a nullptr value which is not acceptable might be subjected to a qWarning, while just outputting a value so that you know what it is might be a qDebug.

      1 Reply Last reply
      3
      • ashajgA ashajg

        hi guys

        I want to do some study on qDebug(), qWarning(), qFatal() and qCritical.
        I went through this document https://doc.qt.io/qt-5/qtglobal.html#qCritical
        What is exact difference in all 4 and how to effectively use them in program?
        I wrote a small code

        code :

        if(c == 100)
           {
               qDebug()<<"Value is "<<c;
               qInfo()<<"INFO VALUE is";
               qCritical()<<"qWarning";
               qFatal("fatal error");
               qDebug()<<"Value is "<<c;
           }
        

        **output:

        Value is 100
        INFO VALUE is
        qwarning
        qCritical
        fatal error**

        so I got to know that qFatal will terminate the program but how I can use qWarning, qCritical or qInfo effectively as i cannot see any difference in logs of qWarning, qCritical , qInfo and qDebug.

        Thanks and Regards
        Ashish

        aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @ashajg see also the "new" feature of categorized logging: https://blog.qt.io/blog/2014/03/11/qt-weekly-1-categorized-logging/

        Qt has to stay free or it will die.

        ashajgA 1 Reply Last reply
        4
        • aha_1980A aha_1980

          @ashajg see also the "new" feature of categorized logging: https://blog.qt.io/blog/2014/03/11/qt-weekly-1-categorized-logging/

          ashajgA Offline
          ashajgA Offline
          ashajg
          wrote on last edited by
          #4

          @aha_1980 @JonB Thank you guys!!!

          JonBJ 1 Reply Last reply
          0
          • ashajgA ashajg

            @aha_1980 @JonB Thank you guys!!!

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @ashajg
            @aha_1980 's logging by categories (I didn't know Qt had that) is exactly the kind of thing I do in my own code (in qtMessageHandler) to achieve logging-by-individual-categories. It helps a lot if you put something like this in as you develop: it's much better to be able to switch on info message for, say, just your database accesses rather than having to switch all info message for whole program on/off.

            1 Reply Last reply
            2

            • Login

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