PDA

View Full Version : cout to stdout in Qt Console Application



tuli
28th February 2013, 15:29
What is the right way to write to stdout in a Qt Console Project?

This appears to be a popular question, which is commonly answered with "use qDebug() << QString(...)".
Indeed, that is exactly what i want, but qDebug() writes to stderr, not stdout.

What would be the stdout equivalent to qDebug()?

alainstgt
28th February 2013, 18:10
#include <QTextStream>

. . .

QTextStream cout(stdout);

wysota
28th February 2013, 23:14
What is the right way to write to stdout in a Qt Console Project?


std::cout << "xyz" << std::endl;

alainstgt
6th March 2013, 13:51
with QTextStream you can also use Qt objects. Things like



#include <QTextStream>
....
QTextStream cin(stdin);
QTextStream cout(stdout);

cout << "Enter your name: " << endl;
QString s = cin.readLine();
cout << "Your name is: " << s;