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";}
#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
-
Hi,
Have a look at qCDebug() instead of qDebug() :) http://qt-project.org/doc/qt-5/qloggingcategory.html#qCDebug
-
this does not help .. QCDebug is a logging mechanism and not what i need .. how should i use it to represent loglevel?
-
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. -
thank you, it seems much easier now.. I will give it a try
but how about not being compiled if no debug is requested ???