Hi, I'm new in Qt programming and I've and issue using QProcess class.
I've to build a GUI for a C console program. I need to be more modular possible, so I thought to build the GUI based on the use of QProcess, redirecting stdin/stdout on the GUI.
I tryed with a simple helloworld.c program
#include <stdio.h>
int main(void){
int number;
printf("Hello! Write a number:\n");
scanf("%d",&number);
printf("You wrote %d", number);
return 0;
}
the I wrote the program:
proc= new QProcess(this);
connect(proc, SIGNAL(readyReadStandardOutput()),this, SLOT(rightMessage()) );
connect(proc, SIGNAL(readyReadStandardError()), this, SLOT(wrongMessage()) );
proc->start("./helloworld", QIODevice::ReadWrite);
void tesQProcess::on_btnProcess_clicked()
{
QString str_command;
str_command = ui->lineeCommand->text();
proc->write(str_command.toAscii());
}
btnProcess is defined in the .ui file.
The program should start helloworld, print into my GUI "Hello! Write a number:", then I should write a number into lineCommand and press the button to see the final print: You wrote 6.
When I run the program, I get no initial output (Hello! Write a number: ).
Only after I write the number and the program linked to QProcess ends I get all the output (Hello! Write a number: Your wrote 6).
Am I missing something? How could I get sinchronized output?
Thanks for you help and sorry for my bad english