PDA

View Full Version : QProcess, readyRead, QTextEdit



sgrant327
31st January 2011, 21:17
I want to be able to 'continuously' append the output of a command-line into a QTextEdit.

I have a GUI app that uses QProcess to start a command-line app. The CL app has tons of output via printf's.

I am current connecting to the readyRead() signal of the QProcess and using readAllStandardOutput() to post the info into the QTextEdit. The problem with this is that I only get the output once the CL app is finished.

What do I need to do to get the output as it happens?

TIA, Sam.

high_flyer
1st February 2011, 09:48
what happens if you use the readyReadStandardOutput () signal instead?

stampede
1st February 2011, 09:58
The CL app has tons of output via printf's
Is it your command line application ? If yes, you may consider flushing the stdout after printf:


printf("A text");
fflush(stdout);


stdout is buffered, but it should flush automatically after reaching new line character.

Also try to set read channel for QProcess:

proc->setReadChannel(QProcess::StandardOutput);

sgrant327
1st February 2011, 16:28
Got it working better...

printf and fflush and QProcess::StandardOutput and readyReadStandardOutput () did the trick.

stampede
1st February 2011, 16:49
printf and fflush (...)
I think you can even disable buffering of the stdout in your app:

setbuf(stdout,NULL);