PDA

View Full Version : QTextStream does not read from stdin



MasterBLB
19th November 2012, 09:07
Hello guys

What's wrong with the code below that messagebox displays empty string??


QTextStream stream(stdout);

std::cout<<"bla";
qDebug()<<"ble";

QString line("initial");

line = stream.readLine();

QMessageBox::about(0,0,line);

amleto
19th November 2012, 15:41
what is 'stdout' ? Please read my sig.

MasterBLB
20th November 2012, 08:04
http://qt-project.org/doc/qt-4.8/qtextstream.html#details
That's the example from Qt doc.

amleto
20th November 2012, 11:32
found it by myself,
http://www.cplusplus.com/reference/clibrary/cstdio/stdout/

Added after 11 minutes:

maybe QTextStream doesn't know buffer has changed...



QTextStream stream(stdout);

stream<<"bla";

QString line = stream.readLine();

QMessageBox::about(0,0,line);


I expect that works better...

MasterBLB
20th November 2012, 16:20
That surely works better,but won't help with my goal,which is a Qt GUI program intercepting all what has been sent to standard out and error (ext std::cout << "some input";) then displaying that inside let's say QTextEdit.

anda_skoa
20th November 2012, 18:05
stdout stands for "Standard Output". The example you linked to uses stdin, which stands for "Standard Input".
You can read from an input file handle and write to an output file handle, but only read/write from a file handle that has been opened for read and write.
Neither of the to standard handles has been opened that way.

You could start a wrapper program that uses QProcess to start the real program and read from the standard output of the child.

Cheers,
_