P
P
pixik2015-06-25 10:20:33
Qt
pixik, 2015-06-25 10:20:33

Why doesn't qDebug work in other calls?

Good time!
For some reason, qDebug does not work in calls after the first line of the main body of the code.

#include "mainwindow.h"
#include <QApplication>
#include <QDebug>

int main(int argc, char *argv[])
{
    qDebug() << "1 start" ;
    QApplication a(argc, argv);
    qDebug() << "2 start" ;
     MainWindow w;
    qDebug() << "3 start" ;
    w.show();
    return a.exec();
}

The only output to the console is:
1 start
Here is the entire pro file at the moment:
QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = gui_project
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp \
    myclass.cpp

HEADERS  += mainwindow.h \
    myclass.h

FORMS    += mainwindow.ui

Tell me please, what could be the problem?
Thanks to all!

Answer the question

In order to leave comments, you need to log in

5 answer(s)
V
Viktor Shakhov, 2017-09-29
@skaff

I had the same situation. Additionally, it turned out that std::cout behaves similarly, but qWarning() is quite efficient.
The decision found at one foreign forum helped. Successfully worked in my installation with qt.io.
You need to create a file ~/.config/QtProject/qtlogging.ini
And yes, Ubuntu OS.

A
Anthony, 2015-06-25
@RiseOfDeath

I bet it will work if you put it after the line QApplication a(argc, argv); ?
I did not find an explicit explanation in the documentation, but I suspect that its work is somehow tied to event loops and, as a result, you need an event loop (i.e. either QApplication or QCoreApplication)

V
Vitaly Filinkov, 2015-06-25
@vitfil

And why did you decide that it is not displayed? Start the console, run your application from the console and check that everything is output. Windows, did I guess correctly?

X
xibir, 2015-06-25
@xibir

qDebug has stopped working in recent versions of gdb. If you just run it in the console without a debugger, it will work.
https://sourceware.org/bugzilla/show_bug.cgi?id=18164

P
podkyr, 2021-03-12
@podkyr

I also encountered that QDebug() calls were only visible from main.cpp. My application was with QML, and as it turned out, in order for QDebug to work inside some class, you need to register it via
engine.rootContext()->setContextProperty( );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question