qDebug not displaying anything
Asked Answered
H

9

15

Often when I need to debug something it's easier to print something using qDebug() instead of debugging step-by-step using a debugger. The problem is that from time to time the output of qDebug() isn't displayed at all! The same with qWarning and qCritical. What's strange, it only occurs when running the project normally (Ctrl+R), while when debugging (F5) the output shows up.

Honorine answered 9/10, 2012 at 12:6 Comment(0)
H
16

The solution is simple: add CONFIG += console to your .pro file and rebuild the whole project.

Honorine answered 9/10, 2012 at 12:6 Comment(0)
N
12

Solution for me, As stated in https://bugzilla.redhat.com/show_bug.cgi?id=1227295#c10 was :

  1. look for qtlogging.ini in /etc/xdg/QtProject/ .
  2. edit the current (or create the file qtlogging.ini if missing)
[Rules]
*.debug=false

to

[Rules]
*.debug=true
qt.*.debug=false
  1. recompile and check!
Nippur answered 1/6, 2018 at 19:44 Comment(3)
is working for me - seems that this entry is disabling the QDebug in recent systems like ubuntu 18.xxSalamander
im not sure if thats the cause, but i forgot to mention that i was on Ubuntu 17.10 and Qt 5.9Nippur
Also works if I put it in ~/.config/QtProject/qtlogging.iniNylanylghau
S
7

I had the same problem and none of the answers here did help me. I found the solution here: https://lists.fedoraproject.org/archives/list/[email protected]/thread/SB6QJZGVDLWWBZCMTNKMVZSSPPNREOYJ/

I had to set the environment variable QT_ASSUME_STDERR_HAS_CONSOLE=1. This can be done in code:

qputenv("QT_ASSUME_STDERR_HAS_CONSOLE", "1");

Or better in the "Kits" settings under "Environment".

Straphanger answered 21/10, 2021 at 6:18 Comment(1)
Took me hours to get here. I used Qt to crosscompile for windows 10, but qDebug did not display anything. I was using cLion as the IDE as Qt environment does not fit me. Using the above in Qt Widget application fixed this.Avestan
B
5

If you are running multiple instances of Qt Creator, qDebug does not work properly.

Bobble answered 1/4, 2015 at 14:58 Comment(0)
B
1

My solution for this problem using

Windows 10 Education
Qt Creator (5.x)
Developing a Qt widget.

Problem:

So my issue was whenever I added a QDebug message it didn't show up in the application output although my code was 100% the same as in the tutorial and compiled fine.

Solution:

Right click on the file where you added the QDebug message, for me it was main.cpp. Click build. Press the green arrow on the bottom.

If this still doesn't work go to "Build"->"CleanAll", "Build"->"qMake" and go for the green arrow again.

Of course you have to #include <QDebug> and check that it is well spelled inside your code.

Borderland answered 26/10, 2015 at 23:3 Comment(0)
W
0

In my case, it is somehow I forgot to click the 'Configure Project'. I am using QTCreator 4.11 and Qt5.14. When I create the project, I did not click on the 'Configure project' near the end of the creation process.

Wellthoughtof answered 28/3, 2020 at 11:33 Comment(0)
B
0

Qt5.14.2, QtCreator 4.12.0: What worked for me was to unselect Projects->Run->Run in Terminal... Duh!

Banderole answered 30/4, 2020 at 0:47 Comment(0)
L
0

You have to configure the logging rules. See documentation.

The format is:

    <category>[.<type>] = true|false

Logging rules are automatically loaded from the [Rules] section in a logging configuration file. These configuration files are looked up in the QtProject configuration directory, or explicitly set in a QT_LOGGING_CONF environment variable:

    [Rules]
    *.debug=false
    driver.usb.debug=true

Logging rules can also be specified in a QT_LOGGING_RULES environment variable; multiple rules can also be separated by semicolons:

    QT_LOGGING_RULES="*.debug=false;driver.usb.debug=true"

For example:

QT_LOGGING_RULES="*.debug=true;qt.*=false"
Loophole answered 10/6, 2022 at 10:13 Comment(0)
N
0

Solved by adding:

export QT_ASSUME_STDERR_HAS_CONSOLE=1

to qtcreator start script placed in:

/home/yourUsername/qtcreator-10.0.0/bin/qtcreator.sh

provided by application downloaded from official site.

#! /bin/sh

export QT_ASSUME_STDERR_HAS_CONSOLE=1

# Use this script if you add paths to LD_LIBRARY_PATH
# that contain libraries that conflict with the
# libraries that Qt Creator depends on.

makeAbsolute() {
    case $1 in
        /*)
            # already absolute, return it
            echo "$1"
            ;;
        *)
            # relative, prepend $2 made absolute
            echo `makeAbsolute "$2" "$PWD"`/"$1" | sed 's,/\.$,,'
            ;;
    esac
}
..
//some lines...
..
export LD_LIBRARY_PATH
exec "$bindir/qtcreator" -user-library-path "$_ORIGINAL_LD_LIBRARY_PATH" ${1+"$@"}.

Update: Above solution is valid for Qt Creator. Using a terminal like xterm for starting, detached, a Qt application that use QProcess class for starting another Qt application (in my case in a project with more than one subprojects), readyReadStandardError() signal in the first one get correctly stderr of the second until terminal is closed when communication between processes broken. I solved this second problem adding

     qputenv("QT_ASSUME_STDERR_HAS_CONSOLE", "1");

in main.cpp so:

    #include "frmparman.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        qputenv("QT_ASSUME_STDERR_HAS_CONSOLE", "1");
        a.setStyle("windows");
        frmParman w;
        w.show();
    
        return a.exec();
    }
Nicholle answered 23/6, 2023 at 12:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.