Unsolved change qDebug display level at runtime after program startup
-
Does anyone know if it is possible to change the display of statements of qDebug() duration execution as opposed to startup?
https://stackoverflow.com/questions/28540571/how-to-enable-and-disable-qdebug-messages
-
@James-Mark-Chan
As described in the link you reference, allqDebug()
statements go via https://doc.qt.io/qt-5/qtglobal.html#qInstallMessageHandler, where you can do whatever you like at runtime with appropriate code. What is it that you cannot achieve that way? -
Looks like calling qInstallMessageHandler(myMessageOutput); replaces the default message handler which I believe will work for us. I though it added a message handler in addition to the default one and the default one could be configured further in some way.
-
@James-Mark-Chan
You can indeed only have one message handler. CallingqInstallMessageHandler()
replaces any current one. The docs state:Only one message handler can be defined, since this is usually done on an application-wide basis to control debug output.
However, because the method returns a
QtMessageHandler
Installs a Qt message handler which has been defined previously. Returns a pointer to the previous message handler.
[My bold.] That means if you had a current/previous one which you still wanted under whatever circumstances, save this returned pointer and use it from your newly-installed one to call the original code in addition/instead of/as appropriate.