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. Simple qdebug question

Simple qdebug question

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 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.
  • S Offline
    S Offline
    SherifOmran
    wrote on last edited by
    #1

    Hello guys,

    i need to change the normal qdebug()<<"test" into a function which indicates the debug level and compiles if only debugmode is set,
    Something like the following
    @
    #ifdef DEMODEBUG
    if (DebugLevel==2){qDebug()<<"test";}
    #endif
    @
    I should call the function the same way as normal but with debug level between brackets in order to simplify editing ..
    @
    qDebug(3)<<"test level";
    @

    I don't know if it is possible to do .. how would the function header look like? .. help is appreciated, thanks

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi,

      Have a look at qCDebug() instead of qDebug() :) http://qt-project.org/doc/qt-5/qloggingcategory.html#qCDebug

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SherifOmran
        wrote on last edited by
        #3

        this does not help .. QCDebug is a logging mechanism and not what i need .. how should i use it to represent loglevel?

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          qDebug() is a logging mechanism too. qCDebug() is just a more powerful version of qDebug().

          You asked for a way to set debug levels with less code than your first post. Well, logging-categories let you do that.

          @
          Q_DECLARE_LOGGING_CATEGORY(DBG_LVL1)
          Q_LOGGING_CATEGORY(DBG_LVL1, "dbg_lvl1")

          #define D1ENABLED true

          int main()
          {
          // This line only needs to be called once.
          // You can then use qCDebug(DBG_LVL1) in your whole app.
          DBG_LVL1().setEnabled(D1ENABLED);

          qCDebug(DBG_LVL1)  << "test";
          
          return 0;
          

          }
          @
          You will get an output if D1ENABLED is true. Otherwise, you won't get an output.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SherifOmran
            wrote on last edited by
            #5

            thank you, it seems much easier now.. I will give it a try
            but how about not being compiled if no debug is requested ???

            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