Reputation: 1166
I disable the qDebug() messages by writing
CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT
in the .pro file. This works fine. I would like to know if there is any way to enable qDebug() messages using the source code. I would like to send it as an argument to the application. Therefore by default I will have the qDebug() messages disabled, but with an argument stating to switch on the qDebug() messages I need the qDebug() enabled. Is it possible to do this?
Any help is appreciated
Upvotes: 23
Views: 40240
Reputation: 1322
Adding this code to my qmake project file enabled qDebug() messages for release builds on Windows/MSYS, even without the qInstallMsgHandler():
CONFIG += console
CONFIG += warn_on
Upvotes: 1
Reputation: 191
You can control QDebug (and all messages) at runtime via a few options:
QT_LOGGING_RULES="*.debug=false;driver.usb.debug=true"
turns on qDebug for everything except USB debug. If you need a more complicated setup, or if you are using Qt 5.5 or earlier you can turn on and off individual debug messages via a qtlogging.ini file.Upvotes: 17
Reputation: 5718
You can add your own function for handling Qt debug messages with qInstallMsgHandler
This will allow you to control whether to print the messages.
Upvotes: 11