Qt qDebug not working with QConsoleApplication or

2019-02-05 09:41发布

I currently have a terribly annoying problem while developing programs using Qt and Qt Creator. Whenever I try using qDebug() with a QCoreApplication or QApplication instantiated before using qDebug(), there isn't any output, whether I run the program in Qt Creator or from a normal shell(I'm using Fedora Linux btw). For example, even the following simple code fails:

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    qDebug() << "TestOutput!" << endl;
}

Does anybody know what to do about this problem? Thanks in advance, Marius

4条回答
不美不萌又怎样
2楼-- · 2019-02-05 10:23

OK, I found out what the problem was, it was indeed Fedora, but it's the new standard configuration. See here: https://forum.qt.io/topic/54820/

查看更多
ゆ 、 Hurt°
3楼-- · 2019-02-05 10:27

This one help for me (In user bashrc file):

export QT_LOGGING_DEBUG=1
查看更多
家丑人穷心不美
4楼-- · 2019-02-05 10:37

For better formatting, I add this new solution, marius still found it himself in this bugzilla.

Edit ~/.config/QtProject/qtlogging.ini and add:

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

The last line is to disable spammy debug logging for moved mouse messages.

查看更多
Explosion°爆炸
5楼-- · 2019-02-05 10:43

Docs around this can be found here: http://doc.qt.io/qt-5/qloggingcategory.html#details

It can be configured in many ways. Few useful examples:

by env variable(cmd):

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

by env variable(export):

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

or in code:

#include <QCoreApplication>
#include <QLoggingCategory>
int main(int argc, char *argv[])
{
  QCoreApplication a(argc, argv);
  QLoggingCategory::setFilterRules("*.debug=true");
  qDebug() << "Debugging;
  a.exit();
}
查看更多
登录 后发表回答