Sachin Palande
Sachin Palande

Reputation: 27

How to disable qInfo() output

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.

Upvotes: 0

Views: 1333

Answers (2)

Moia
Moia

Reputation: 2354

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

Upvotes: 1

thibsc
thibsc

Reputation: 4049

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

Upvotes: 2

Related Questions