I'm trying to use QProcess to interact with a very simple external application on Linux that takes some input using scanf and outputs results using printf.

My understanding is that I can use the the signal "ReadyReadStandardOutput" to tell me when my external app has some text output ready for me to read, and I can then send it some text using write() and that will go into the scanf() of the application.

However it doesn't actually output any text to my "ReadyReadStandardOutput" slot until the application has quit. Then I get a buffer with all of the text output from the prinf().

For example in my external app:

Qt Code:
  1. printf("enter a number\n");
  2. scanf("%d",&number);
  3. printf("you entered %d",number);
To copy to clipboard, switch view to plain text mode 

I don't get anything until I call
Qt Code:
  1. myProcess->write("4\r");
To copy to clipboard, switch view to plain text mode 
,then I suddenly get:
Qt Code:
  1. enter a number
  2. you entered 4
To copy to clipboard, switch view to plain text mode 

I was expecting that I should get "enter a number" as soon as I start the QProcess.

I'm using QProcess as follows:

Qt Code:
  1. myProcess = new QProcess(this);
  2. connect(myProcess,SIGNAL(readyReadStandardOutput()), this, SLOT(data_ready()));
  3. myProcess->start("testapp");
  4. if (!myProcess->waitForStarted(5000))
  5. {
  6. return -1;
  7. }
To copy to clipboard, switch view to plain text mode 


Am I misunderstanding how QProcess should work?