I\'ve found similar questions but never the exact answer. I have Qt program that starts a QProcess and writes the output to a QTextEdit box, so far so good. But it only does
In an ideal world there would be some sort of signal that QProcess emits when there is a line ready to read
Is the Qprocess
signal readyReadStandardOutput()
not exactly what your asking for ?
You can connect to it then is your slot get the available data bytesAvailable()
and look for the '/n'
chars. Or simply readLine()
while canReadLine()
.
Do not forget to start your process and don't wait for it to finish. Plus set-up the ProcessChannelMode
to SeparateChannels
.
EDIT
I do have a class that read line of a QProcess
like this :
bool extProcess::logReady()
{
while( proc->canReadLine())
{
QByteArray line = proc->readLine();
/*do some with the line like copying it's content to a QTextEdit*/
}
}
And it work quite well. I not sure about the emit outLog()
signal ! Are you try to pass a QByteArray
through a signal ? The data contained in the QByteArray
must be save in a buffer and you should pass the pointer to this array to anyone connected to it ...
But again if you don't want to use extra memory and deal with the "is the data consumed ? ... ", do what you need to do with the data in your logReady()
method.