0

I have follwing code snippet to run. In which I want to see result of qDebug() but I dont want see result of qInfo(). I want to configure it on basis, sowetimes I need those qInfo() output and sometimes not.

    qInfo()<<"Info print";
    qDebug()<<"Debug print";

In above code, I want only 'Debug print' should print. but can't comment qInfo() line.

thibsc
  • 3,747
  • 2
  • 18
  • 38

2 Answers2

2

As it described on the Qt debug documentation, you have to compile with QT_NO_INFO_OUTPUT to disable it.

# your .pro file
DEFINES += QT_DEPRECATED_WARNINGS QT_NO_INFO_OUTPUT

You can also use define for other macro:

qDebug(): disable with QT_NO_DEBUG_OUTPUT
qInfo(): disable with QT_NO_INFO_OUTPUT
qWarning(): disable with QT_NO_WARNING_OUTPUT
qCritical(): enable with QT_FATAL_CRITICALS

thibsc
  • 3,747
  • 2
  • 18
  • 38
1

You can choose at runtime which category enable (even for custom category) with QLoggingCategory::setFilterRules

From Qt Docs, exampe with custom category:

QLoggingCategory::setFilterRules(QStringLiteral("driver.usb.debug=true"));

For your case:

QLoggingCategory::setFilterRules(QStringLiteral("*.info=false"));

take care of using "*.info=true" because enable everything, even for profiling category usually disablet

Moia
  • 2,216
  • 1
  • 12
  • 34