cout does no print in QtCreator

18,429

Solution 1

Try with:

cout << "asdf" << endl;

Possibly Qt sets up iostream in order to flush only at new line.

Solution 2

When debugging with CDB (Windows debugger) and running application not in the dedicated terminal window, but within QtCreator output panel, there is an issue with std::cout/std::cerr. qDebug works because it has a trick for this case. So, the only solution in this case is enable the "run in terminal" option. For more infor please follow the link above to the Qt bug tracker.

Solution 3

Is it possible that STDOUT is redirecting? qDebug prints to STDERR by default.

Solution 4

Did you #include <iostream>? I did not see any includes in the code. I assume that qdebug and cout are very similar.

Share:
18,429
Stefano
Author by

Stefano

C++ Software engineer working in control systems for particle accelerators.

Updated on June 04, 2022

Comments

  • Stefano
    Stefano almost 2 years

    I saw this question already on this forum but I do not know why the proposed answer does not work in my case. So I try to ask for other slution.

    I just got my Qt creator running under Linux.

    I do not understand why my:

    cout << "This does not appear";
    

    Does not print in console while qdebug does

    qDebug() << "This appears";
    

    This is what is contained in my .pro file:

    QT       += core gui
    
    TARGET = aaa
    TEMPLATE = app
    
    
    SOURCES += main.cpp\
            mainwindow.cpp \
        IeplcModule.cpp
    
    HEADERS  += mainwindow.h \
        IeplcModule.h
    
    FORMS    += mainwindow.ui
    
    #enable console
    CONFIG += console
    

    Any idea?

  • Austin Henley
    Austin Henley over 11 years
    This question has already been solved by the accepted answer.
  • RajaRaviVarma
    RajaRaviVarma over 11 years
    +1 For the correct answer and explanation, by the way you didn't suggest using qDebug() as everyone did.
  • steffen
    steffen about 8 years
    Actually, endl is a newline plus flush command. Similar to "\n" << flush