解决Qt5 qDebug()不显示调试信息

之前不知怎么,Qt qDebug() 无法输出调试信息,不过诸如
qWarning() qCritical() 可以正常输出

方法

之前我是用 qInstallMessageHandler(QtMessageHandler) 捕获信息,同样也是无法输出 qDebug() 的信息.

最后还是在Qt官网论坛发出帖子寻求帮助
https://forum.qt.io/topic/86358/qdebug-can-t-output-text

从这个网站找到解决方法 https://brendanwhitfield.wordpress.com/2016/06/08/enabling-qdebug-on-fedora/

When writing Qt applications, it’s helpful to use a qDebug() statement once in a while. However, I’ve recently found that qDebug() on stock Fedora no longer prints, while qWarning() does. The first thing that the internet tells you is to add CONFIG += console to your .pro file, but alas, this is not the solution. It turns out, because of the way Qt is setup on Fedora, debug output is no longer emitted on stderr (by design). Thanks to this bug report, the solution is to create the following file in either of these locations:

  • ~/.config/QtProject/qtlogging.ini (for your user only)
  • /etc/xdg/QtProject/qtlogging.ini (system-wide)

[Rules].debug=trueqt…debug=false

The first rule enables all debug output, while the second disables Qt’s internal debug statements. This prevents a deluge of output from Qt when debugging your application.

我修改 /etc/xdg/QtProject/qtlogging.ini 文件

*[Rules] .debug=true
qt.*.debug=false

bye~