Qt调试不工作与QConsoleApplication或QApplication

Qt qDebug not working with QConsoleApplication or QApplication

本文关键字:QConsoleApplication QApplication 工作 调试 Qt      更新时间:2023-10-16

在使用Qt和Qt Creator开发程序时,我目前有一个非常烦人的问题。每当我尝试在使用qDebug()之前使用QCoreApplicationQApplication实例化qDebug()时,无论我是在Qt Creator中运行程序还是从正常shell(我使用Fedora Linux btw)中运行程序,都没有任何输出。例如,即使下面的简单代码也会失败:

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    qDebug() << "TestOutput!" << endl;
}
有谁知道该怎么解决这个问题吗?提前感谢,马吕斯

为了更好的格式化,我添加了这个新的解决方案,marius仍然在这个bugzilla中找到了它。

编辑~/.config/QtProject/qtlogging.ini并添加:

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

最后一行是禁用moved mouse消息的垃圾调试日志。

相关文档可以在这里找到:http://doc.qt.io/qt-5/qloggingcategory.html#details

它可以通过多种方式配置。几个有用的例子:

by env variable(cmd):

$ export QT_LOGGING_RULES="*.debug=true" ./app

by env variable(export):

$ QT_LOGGING_RULES="*.debug=true"
$ ./app

或在代码中:

#include <QCoreApplication>
#include <QLoggingCategory>
int main(int argc, char *argv[])
{
  QCoreApplication a(argc, argv);
  QLoggingCategory::setFilterRules("*.debug=true");
  qDebug() << "Debugging;
  a.exit();
}

好的,我找到了问题所在,它确实是Fedora,但它是新的标准配置。在这里看到的:https://forum.qt.io/topic/54820/

这个对我有帮助(在用户bashrc文件中):

export QT_LOGGING_DEBUG=1
相关文章:
  • 没有找到相关文章