View Full Version : QProcess and windows CreateProcess, read line by line

10th August 2010, 07:06
I am rewriting my application from Borland to Qt. It calls an exe and pipes the output to the app. Originally I used CreateProcess, PeekNamedPipe etc. but these are native to windows and not multiplatform. I want to use QProcess and do not get very far. My simple code:

calcProcess = new QProcess(this);
connect(calcProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readFromStdout()) );

and in readFromStdout():

QString output;
output = calcProcess->readAllStandardOutput();
outputedit->appendPlainText(output); //outputedit is a PlainTextEdit

This seems to fill an output buffer (4096 bytes?) and the output is appended when the output buffer is full. I would then have to parse the output breaking it into strings with split or something.
I have read that the signal is triggered each time the external exe produces something, and I want to read this output each time (per line). I have looked at many pieces of code in the forum but can't find how to do this. Thanks.

10th August 2010, 07:11
Since QProcess is a QIODevice, you can just use readLine();

10th August 2010, 08:25
Thanks, trying. It seems the app outputs everything on the error channel because there is no output on the stdout channel! In the code above I use in fact 'calcProcess->readAllStandardError();' sorry for miswriting that.
In a dosbox the output looks like "Executing timestep n" where n is a number.
Both readLine and readAllStandardError() give the output twice:
Executing timestep 3
Executing timestep 3
Executing timestep 4
Executing timestep 4
Also the readLine just fills up the buffersize that I give (so it acts like readAllStandardError) and does not seem to see a '\n' but the output breaks into lines like the ones shown (I tried writing to a file and to PlainTextEdit). Any ideas?

13th August 2010, 11:50
sorry, not a Qt problem but related to the programme I am calling