8

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

marius_linux
  • 595
  • 4
  • 14
  • are you building in debug mode? – Frank Osterfeld Jun 01 '15 at 22:56
  • Provide the whole code. – Murat Şeker Jun 01 '15 at 23:00
  • I can't reproduce your problem with the code you provided. It even works with a release build. – Carlton Jun 02 '15 at 01:16
  • And where you are looking for your output? – demonplus Jun 02 '15 at 04:21
  • The output used to show up in the second console window opened by Qt Creator. I've looked in "Application Output" tab in Qt Creator too, but still nothing. Neither Debug nor Release mode produce the desired output(but some days ago, they used to, and I haven't changed anything regarding Qt since then). Even this small snipped does not work. – marius_linux Jun 02 '15 at 09:48
  • I tried compiling it outside Qt Creator using 'qmake-qt5 CONFIG+=debug' and then 'make', but still: no output. – marius_linux Jun 02 '15 at 09:54
  • You can check whether `QT_NO_DEBUG_OUTPUT` is defined in your `.pro` file like this `DEFINES += QT_NO_DEBUG_OUTPUT` or you might have `#define` it somewhere in your code. If it is there, remove that piece of code. – Ankit Jun 02 '15 at 13:39
  • Checked that, found nothing. I've also tried adding a different message handler, but it does seem as it never gets called. I believe this problem has something to do with my system's configuration, but I can't figure out what the problem is. – marius_linux Jun 02 '15 at 16:41
  • My answer to this question is documented well in this post: https://stackoverflow.com/questions/26295325/where-is-located-the-qdebug-qwarning-qcritical-and-qfatal-log-by-default-on-qt – Dan Jun 05 '17 at 20:35

4 Answers4

9

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.

Mathias
  • 1,470
  • 10
  • 20
5

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();
}
5n00py
  • 199
  • 2
  • 7
  • this worked great for me - although I ended up using 'default.debug=true' to avoid having everything except my own application eject debug messages – GeekyDeaks Nov 28 '17 at 11:33
  • If you get flooded with debug messages from specific modules, providing you with, e.g., information about mouse movement, you can specify multiple filters in the environment variable. For example: QT_LOGGING_RULES="*.debug=true;qt.widgets.gestures.debug=false" – Ole Wolf Nov 30 '17 at 10:39
1

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/

Mathias
  • 1,470
  • 10
  • 20
marius_linux
  • 595
  • 4
  • 14
  • Like suggested in the bugzilla, I added `~/.config/QtProject/qtlogging.ini` containing `[Rules] *.debug=true qt.qpa.input*.debug=false` The last line is to disable "mouse moved" messages everywhere. – Mathias Aug 17 '15 at 06:59
0

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

export QT_LOGGING_DEBUG=1
Šerg
  • 793
  • 5
  • 18