3

I have this simple code

#include <QtCore/qdebug.h>
#include <QtCore/qcoreapplication.h>
#include <iostream>
using namespace std;

int main(int argc, char **argv)
{
    cout << "pluto" << endl;
    QCoreApplication app(argc, argv);
    qDebug() << "pippo" << endl;
    return app.exec();
    //return 0;
}

I compiled it with MinGw in Eclipse with no errors, but when I run the code no string message appear on the consolle. What is wrong? Thanks.

Luca

Tim Meyer
  • 12,210
  • 8
  • 64
  • 97
lukigno
  • 31
  • 1

2 Answers2

3

For cout to work on Windows, you need to have CONFIG+=console in the .pro file. It shouldn't have any effect on any other platform, so you can just add it there. You can use qmake conditionals if you only want it for debug builds or something., or you can pass it to qmake as command line option, if it is more convenient for your workflow:

qmake ...other args... CONFIG+=console

Under Windows, qDebug() output by default goes to Windows debug logs. You can get it in two ways:

hyde
  • 60,639
  • 21
  • 115
  • 176
0

If you really need have that on output, you can try with QTextSteam:

#include <QTextStream>

QTextStream cout(stdout);
cout << "string\n";

QTextSteam cerr(stderr);
cerr << "error!\n";
agilob
  • 6,082
  • 3
  • 33
  • 49