This problem bothers me because it should work, but unfortunately it is not. What I'm trying to achieve is to read the standard output of a specific process and make another process process it, i.e. Print it out.
The process creating the output is as follows:
#include <stdio.h> #include <stdlib.h> #include <iostream> int main() { for (int i = 0; i < 100; i++) { printf("yes %d\n",i); fflush(stdout); sleep(1); } return 0; }
The process starts in another application as follows:
#include <QProcess> ... QProcess * process = new QProcess; SomeClass * someClass = new SomeClass(process); connect(process,SIGNAL(readyRead()),someClass,SLOT(onReadyRead())); process->start("../Test/Test",QStringList()); if (!process->waitForStarted(4000)) { qDebug() << "Process did not start."; } ... void SomeClass::onReadyRead() { qDebug() << "Reading:" << process->readAllStdOutput(); }
My expected result:
Reading: yes 0 Reading: yes 1 ... Reading: yes 99
However, I am not getting any output. And when I use QCoreApplication, I get all the output, but not through the signal / slot, but directly in the console.
I do not understand, because it works in another application using Qt 4.8.
My question is, is anyone experiencing the same problem or does anyone know how I can get the expected behavior?
source share