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. How to selectively reenable qDebug ?
Forum Updated to NodeBB v4.3 + New Features

How to selectively reenable qDebug ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 4 Posters 898 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1

    I can disable ALL qDebug messages in .pro file

    DEFINES += QT_NO_DEBUG_OUTPUT

    I understand qDebug is a actually macro including
    #ifdef ..#endif directive

    I like to be able to reenable qDebug or derivation of it AFTER all other qDebug code is disabled using the above "DEFINES"

    I like to have debug prints for part of the code and just adding
    #ifdef DEBUG_THIS
    qDebug(....
    #endif

    does not do the job if I have DEFINES += QT_NO_DEBUG_OUTPUT in .pro file.

    Ideally - if it is possible - I like to wholesale add another flag to the qDebug macro , something to additionally enable it using preprocessor directive ::

    #ifdef ENABLE_ ALL_ DEBUG
    qDebug...

    #endif

    I think I know how to search and replace
    qDebug()

    with
    #ifdef ENABLE_ ALL_ DEBUG
    qDebug...

    but not sure how to add
    #endif

    Any other less chancy ( search and replace ) solution ?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Seems like you are just looking for QLoggingCategory

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      1
      • A Offline
        A Offline
        Anonymous_Banned275
        wrote on last edited by VRonin
        #3

        Thanks, perfect solution, albeit confusing implementation.
        I just need selective debug , do not need "warnings " etc.

        I did this test :

        #define DISABLE_QDEBUG
        #define CATEGORY_MAIN
        
        //#undef DISABLE_DEBUG
        MainWindow::MainWindow()
            : mdiArea(new QMdiArea)
        {
        // test  QLoggingCategory
           QLoggingCategory category("driver.usb");
           qCDebug(category) << "Q_FUNC_INFO" <<Q_FUNC_INFO << "TEST debug message";
           QLoggingCategory category_main("MainWindow debug ");
        #ifdef CATEGORY_MAIN
           qCDebug(category_main) << "Q_FUNC_INFO" <<Q_FUNC_INFO << "TEST debug message";
        #endif
        
          qDebug() << Q_FUNC_INFO;
        

        I did read the doc and it really does not explain ( to me and clearly ) the syntax.

        So I copied their "sample" and it surprisingly worked
        without adding #include.
        Then I couldn't find how to disable it so I added "normal "
        preprocessor directive #ifdef .. #endif

        Looks silly, but works.
        PS
        The test will probably only work only in MainWindow - where it is defined - as local function.

        Thanks

        VRoninV 1 Reply Last reply
        0
        • A Anonymous_Banned275

          Thanks, perfect solution, albeit confusing implementation.
          I just need selective debug , do not need "warnings " etc.

          I did this test :

          #define DISABLE_QDEBUG
          #define CATEGORY_MAIN
          
          //#undef DISABLE_DEBUG
          MainWindow::MainWindow()
              : mdiArea(new QMdiArea)
          {
          // test  QLoggingCategory
             QLoggingCategory category("driver.usb");
             qCDebug(category) << "Q_FUNC_INFO" <<Q_FUNC_INFO << "TEST debug message";
             QLoggingCategory category_main("MainWindow debug ");
          #ifdef CATEGORY_MAIN
             qCDebug(category_main) << "Q_FUNC_INFO" <<Q_FUNC_INFO << "TEST debug message";
          #endif
          
            qDebug() << Q_FUNC_INFO;
          

          I did read the doc and it really does not explain ( to me and clearly ) the syntax.

          So I copied their "sample" and it surprisingly worked
          without adding #include.
          Then I couldn't find how to disable it so I added "normal "
          preprocessor directive #ifdef .. #endif

          Looks silly, but works.
          PS
          The test will probably only work only in MainWindow - where it is defined - as local function.

          Thanks

          VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          @AnneRanch said in How to selectively reenable qDebug ?:

          albeit confusing implementation.

          There is a video of Kai explaining how it works: https://www.youtube.com/watch?v=GDtrbIs6JA0&t=1860s

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          1
          • A Offline
            A Offline
            Anonymous_Banned275
            wrote on last edited by
            #5

            Nice , but

            DEFINES += QT_NO_DEBUG_OUTPUT

            disables QLoggingCategory same as it disables qDebug macro.

            I need to visit the QDebug and find out "who is on first" .

            As of now it looks these interact and are controlled by

            QT_NO_DEBUG_OUTPUT

            KroMignonK 1 Reply Last reply
            0
            • D Offline
              D Offline
              DerReisende
              wrote on last edited by
              #6

              Based on QLoggingCategory documentation I guess your #defines should impact setFilterRules() configuration what should be output. Then there should be no reason to #ifdef around qCDebug.
              And you should remove QT_NO_DEBUG_OUTPUT completely if you need the debugging. Otherwise as you already seen you will not get any output even if set up correctly.

              1 Reply Last reply
              0
              • A Anonymous_Banned275

                Nice , but

                DEFINES += QT_NO_DEBUG_OUTPUT

                disables QLoggingCategory same as it disables qDebug macro.

                I need to visit the QDebug and find out "who is on first" .

                As of now it looks these interact and are controlled by

                QT_NO_DEBUG_OUTPUT

                KroMignonK Offline
                KroMignonK Offline
                KroMignon
                wrote on last edited by KroMignon
                #7

                @AnneRanch said in How to selectively reenable qDebug ?:

                DEFINES += QT_NO_DEBUG_OUTPUT
                disables QLoggingCategory same as it disables qDebug macro.

                As written in documentation (https://doc.qt.io/qt-5/qloggingcategory.html#configuring-categories), you can filter the debug output with QLoggingCategory::setFilterRules() or environment variable QT_LOGGING_RULES.

                For example to disable all debug expect the category "mytest":

                • QLoggingCategory::setFilterRules("*.debug=false\nmytest.debug=true"); each rule has to be separated with carriage return (\n)
                • or QT_LOGGING_RULES="*.debug=false;mytest.debug=true", each rule has to be separated with semi-colon.

                It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                1 Reply Last reply
                3
                • A Offline
                  A Offline
                  Anonymous_Banned275
                  wrote on last edited by
                  #8

                  Thank for the replies.
                  My best guess is QDebug is sort of generic class and it works just fine as is.
                  QLoggingCategory is NOT directly related to QDebug and the "category" gives option to direct debugging into specific "area" . Somewhat confusing to use both "category" and "area" terms.
                  I need to read more on QLoggingCategory but it definitely will do what I want.
                  And yes, there is no need to use preprocessor directive and QT_NO_DEBUG_OUTPUT will enable / disable both QDebug and QLoggingCategory . ( After reading few discussions on how QT_NO_DEBUG_OUTPUT works - most users do not see it is "make / qmake " option and NOT preprocessor directive )
                  I think I 'll change my qDebug to "qDebug" category .
                  Then I can add my new "chat debug" as category.
                  Little scary - I have not counted my "qDebug" messages....

                  KroMignonK 1 Reply Last reply
                  0
                  • A Anonymous_Banned275

                    Thank for the replies.
                    My best guess is QDebug is sort of generic class and it works just fine as is.
                    QLoggingCategory is NOT directly related to QDebug and the "category" gives option to direct debugging into specific "area" . Somewhat confusing to use both "category" and "area" terms.
                    I need to read more on QLoggingCategory but it definitely will do what I want.
                    And yes, there is no need to use preprocessor directive and QT_NO_DEBUG_OUTPUT will enable / disable both QDebug and QLoggingCategory . ( After reading few discussions on how QT_NO_DEBUG_OUTPUT works - most users do not see it is "make / qmake " option and NOT preprocessor directive )
                    I think I 'll change my qDebug to "qDebug" category .
                    Then I can add my new "chat debug" as category.
                    Little scary - I have not counted my "qDebug" messages....

                    KroMignonK Offline
                    KroMignonK Offline
                    KroMignon
                    wrote on last edited by
                    #9

                    @AnneRanch said in How to selectively reenable qDebug ?:

                    I think I 'll change my qDebug to "qDebug" category .
                    Then I can add my new "chat debug" as category.
                    Little scary - I have not counted my "qDebug" messages....

                    To be sure to not omit one, you should use qCDebug() instead of qDebug().
                    This will force you to specify a category.

                    It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                    A 1 Reply Last reply
                    2
                    • KroMignonK KroMignon

                      @AnneRanch said in How to selectively reenable qDebug ?:

                      I think I 'll change my qDebug to "qDebug" category .
                      Then I can add my new "chat debug" as category.
                      Little scary - I have not counted my "qDebug" messages....

                      To be sure to not omit one, you should use qCDebug() instead of qDebug().
                      This will force you to specify a category.

                      A Offline
                      A Offline
                      Anonymous_Banned275
                      wrote on last edited by
                      #10

                      @KroMignon Yes, QLoggingCategory has already "default" category and
                      replacing qDebug with qCDebug is putting all qDebug into a category. Nice.

                      1 Reply Last reply
                      0

                      • Login

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