0

I have just start learning Qt using Qt Creator V4.13 and Qt V5.15.1, when I use qDebug(), qInfo(), qWarning() and qCritical() it doesn't show any thing in the application output.

[EDIT] I have checked 'run in terminal' and then clean and rebuild project, it now runs with "qtcreator_process_sub" with the required output of qDebug.

.pro file

    QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    main.cpp \
    mainwindow.cpp

HEADERS += \
    mainwindow.h

FORMS += \
    mainwindow.ui

TRANSLATIONS += \
    ToDo_ar_EG.ts

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

MainWindow.h file

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void addTask();

private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

MainWindow.cpp file

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QtWidgets/QPushButton"
#include "QDebug"
#include <iostream>

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->addTaskButton, &QPushButton::clicked, this, &MainWindow::addTask);
}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::addTask()
{
qDebug()<<"Debug button";
qInfo()<<"Information output";
qWarning()<<"Warning output";
qCritical()<<"Critical output";
}

I have spent two days searching on Google but it all the answers were about undefine QT_NO_DEBUG_OUTPUT but it's defined. what I have tried: include "QtDebug" instead of "qDebug" create qtlogging.ini with content:-

[Rules]
*.debug=true

Tried a clean build (clean and rebuild project) after each edit

specs:

Arch Linux (System is up to date I have just updated it)

V4.13 and Qt V5.15.1

CMake V3.18.2

Make V4.3

QMake V3.1

Nasser
  • 17
  • 10
  • Does this answer your question? [qDebug() doesn't print anything](https://stackoverflow.com/questions/34355549/qdebug-doesnt-print-anything) – Andrew Siplas Mar 28 '21 at 16:20

2 Answers2

1

To see lggoing output you need to:

  1. Configure your project to have a console
  2. Make sure qDebug() isn't disabled by defining QT_NO_DEBUG at build time (switch to a debug build).
  3. Make sure logging isn't disable by system/usr configuration files.
  4. If joining an existing project, check if a qInstallMessageHandler() has been called, in which caset he output may be being redirected somewhere.
  5. If joining an existing project, make sure logging isn't suppressed by calls to setSeverity (not an issue in a fresh Qt Creator project).

Step 1: To configure a console for you application, add

CONFIG += console

to your .pro file, then rerun qmake and rebuild. Alternatively enable "run with a console" in the run configuration gui provided by Qt Creator.

Step 2: switch from a "release" to a "debug" build

For this, you can use Qt Creator's gui on the lower left. This switches CONFIG from "release" to "debug" in the .proj file. Which, among other things, tells qmake not to generate a makefile which calls the compiler with -DQT_NO_DEBUG. Since that would disable qDebug-level logging. Alternatively, edit the .pro file yourself and rerun qmake, then recompile.

Step 3: Check logging configuration files

Since qInfo() doesn't work either on your system, this step probably isn't the problem in your particular case, but it generally can be an issue.

logging can be selectively enabled or disabled via rules set in a system and/or logging configruration file. Since 2015, qDebug() level has been disabled by default on major linux distros (ubuntu, fedora22+) via a system-wide qtlogging.ini which is included in the distro's Qt5 packages.

on my system that means I have a /usr/share/qt5/qtlogging.ini:

$  cat /usr/share/qt5/qtlogging.ini
[Rules]
*.debug=false

To manually override this on the command line, you can set an environment variable from the command line:

$ export QT_LOGGING_RULES='*.debug=true'

$ ./my_program

You can also edit the "build environment" in Qt Creator, if you ant to keep debug output disabled globally, but see it when running in Qt Creator.

I recommended you read QLoggingCategory - Logging Rules for how this can be configured. See also this fedora ticket about the change to disable by default.

mackmist
  • 11
  • 2
0

Just check in Qt Creator under Projects->Run->Run in Terminal if it is checked or unchecked. If it is checked, uncheck it and re-run the program.

smalik
  • 343
  • 4
  • 9
  • It wasn't unchecked, anyway I have checked it and it qtcreator_process_sub appears, and the qDebug messages appear in it correctly, idk if this the expected behavior, when I unchecked it, it backs to not working. – Nasser Sep 14 '20 at 05:31
  • you need a console to see the log. either you do as Sumit suggests or add a console to your app: `CONFIG += console` – seleciii44 Sep 14 '20 at 05:48