Qt5 嘈杂的调试消息"XI2 mouse release ... source MouseEventNotSynthesized"
Qt5 noisy debug messages "XI2 mouse release ... source MouseEventNotSynthesized"
如何抑制 Qt5 调试消息,例如
XI2 mouse motion 331,150, time 188607671, source MouseEventNotSynthesized
在运行我的 GUI 程序的调试版本时淹没控制台?
史前史和分析:在最近将 Debian (buster) 数据包 libqt5core5a 升级到版本 5.9.2+dfsg-6 后,Qt5 不再打印调试消息。qDebug() << ...
和qDebug(...)
都没有工作。在我的程序中,这些消息通过全局函数处理
void messageHandler(QtMsgType type, QMessageLogContext const& ctx, rcstr msg) {
switch (type) {
case QtDebugMsg:
std::cerr << ".... " << msg.toStdString() << /*context(ctx) <<*/ "n" << std::flush;
break;
...
}
}
由语句激活
qInstallMessageHandler(messageHandler);
升级后,qDebug
语句将不再导致调用messageHandler
。
这种不需要的行为是由于文件/etc/xdg/QtProject/qtlogging.ini
,它随libqt5core5a
一起提供,并且具有
[Rules]
*.debug=false
按照 http://doc.qt.io/qt-5/qloggingcategory.html,我用语句覆盖了这些设置
QLoggingCategory::setFilterRules("*.debug=true");
在我的代码中。事实上,我的调试消息再次出现。但是,随之而来的是开场中描述的不需要的消息开始淹没控制台。从Qt文档中可以清楚地看出,过滤规则可以像
QLoggingCategory::setFilterRules("*.debug=true;foo.bar.debug=false");
经过漫长的史前史和分析,我的问题很简单:用什么来代替foo.bar
来摆脱鼠标运动信息?
QLoggingCategory::setFilterRules("*.debug=truenqt.*.debug=false");
这概括了 @G.M. 在评论中指示的答案,并纠正了 Qt 文档中的一个错误:分隔符需要"n"
,而不是";"
。