Qt qDebug not working with QConsoleApplication or QApplication
Asked Answered
U

4

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

Untangle answered 1/6, 2015 at 21:25 Comment(9)
are you building in debug mode?Reach
Provide the whole code.Exemplum
I can't reproduce your problem with the code you provided. It even works with a release build.Doublecheck
And where you are looking for your output?Cynarra
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.Untangle
I tried compiling it outside Qt Creator using 'qmake-qt5 CONFIG+=debug' and then 'make', but still: no output.Untangle
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.Parliamentarianism
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.Untangle
My answer to this question is documented well in this post: #26295825Immediate
B
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.

Brittaney answered 17/8, 2015 at 7:2 Comment(4)
On my system, this file was in /etc/xdg/QtProject/Scuttle
I guess editing the file in /etc/xdg/QtProject/ applies the settings for all users (and needs root for editing) while the path in the answer (create folders/files if missing) is single-user only.Brittaney
On my system (Fedora 29), it is /usr/share/qt5/qtlogging.ini.Olympium
"/usr/share/qt5/" = [QLibraryInfo::DataPath]/qtlogging.ini . This is the documented location for global logging settings.Exhaustive
C
6

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();
}
Copse answered 15/6, 2016 at 19:22 Comment(2)
this worked great for me - although I ended up using 'default.debug=true' to avoid having everything except my own application eject debug messagesAeronautics
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"Dumm
U
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/

Untangle answered 4/6, 2015 at 18:42 Comment(1)
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.Brittaney
B
0

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

export QT_LOGGING_DEBUG=1
Burgos answered 14/2, 2017 at 11:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.