I am trying to read and write from a qprocess right now. I made a little test program that takes input and redisplays it on the screen in a loop. Here is my code from Qt
QString path = "./test";
tcd = new QProcess(this);
QStringList args;
args << "";
tcd->start(path,args);
if(!tcd->waitForStarted(3000))
{
stdoutput->append("<h1><font color=red>There was a problem starting the software, please try running the program again.</font></h1>");
}
tcd->write("hello\n");
tcd->write("hello\n");
tcd->write("hello\n");
tcd->write("hello\n");
//tcd->write("quit\n");
QObject::connect(tcd, SIGNAL(readyReadStandardOutput()), this, SLOT(appendTextBox()));
This won't work unless I send that last quit command (which terminates my test program).
Here's my read command:
void TCD2_GUI::appendTextBox(){
stdoutput->append("new output available: \n");
QByteArray newData = tcd->readAllStandardOutput();
stdoutput->append(QString::fromLocal8Bit(newData));
}
if I send quit, I will get all the output from the program at once, including everything I have sent it.
What am I doing wrong here?
As per request, here is the code from the program:
int main(int argC[], char* argV[]){
printf("Welcome!\n");
char* input = malloc(160);
gets(input);
while(strcmp(input,"quit") != 0)
{
printf("Got input %s\n", input);
gets(input);
}
}
From the doc:
link