Simple qdebug question

  • 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";}
    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

  • Moderators


    Have a look at qCDebug() instead of qDebug() :)

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

  • Moderators

    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_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.

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

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

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

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.