How to suppress Qt5 debug messages like
XI2 mouse motion 331,150, time 188607671, source MouseEventNotSynthesized
that are flooding the console when running a debug release of my GUI program?
Prehistory and analysis: After recent upgrade of Debian (buster) packet libqt5core5a to version 5.9.2+dfsg-6, Qt5 no longer printed debug messages. Neither qDebug() << ...
nor qDebug(...)
worked. In my program, these messages are handled through a global function
void messageHandler(QtMsgType type, QMessageLogContext const& ctx, rcstr msg) {
switch (type) {
case QtDebugMsg:
std::cerr << ".... " << msg.toStdString() << /*context(ctx) <<*/ "\n" << std::flush;
break;
...
}
}
which is activated by the statement
qInstallMessageHandler(messageHandler);
After the upgrade, qDebug
statements would no longer cause invocation of messageHandler
.
This unwanted behavior is due to file /etc/xdg/QtProject/qtlogging.ini
, which comes with libqt5core5a
, and has the contents
[Rules]
*.debug=false
Following http://doc.qt.io/qt-5/qloggingcategory.html I overwrote these settings by the statement
QLoggingCategory::setFilterRules("*.debug=true");
in my code. Indeed my debug messages reappeared. However, along with them the unwanted messages described in the opening began to flood the console. From the Qt documentation it is clear that filter rules can be refined like
QLoggingCategory::setFilterRules("*.debug=true;foo.bar.debug=false");
After this long prehistory and analysis, my question is simply: what to put in place of foo.bar
to get rid of the mouse motion messages?
QLoggingCategory::setFilterRules("*.debug=true\nqt.*.debug=false");
This generalizes the answer indicated in the comment by @G.M., and it corrects a bug in the Qt doc: the separator needs to be "\n"
, not ";"
.