0

I'm new to qt. I'm using qt creator 4.8.1 and am trying to create a gui for a C program that I wrote. The program analyzes files and prints out some information, so my gui would just take that and display it in a text browser. So the idea is once the QProcess prints something I need to read that and display it. I've tried doing it with:

myprocess->waitForReadyRead();
QTextStream(&boxMessage)<<myprocess->readAll();
//display 

I've also tried:

connect(myprocess, SIGNAL(readyReadStandardOutput()), this, SLOT(updateProgress()));
//in updateProgress();
QTextStream(&boxMessage1)<<zerosuppProcess->readAllStandardOutput();

The gui does indeed display the messages, but it displays it all at once. To test this out I created a loop with a message printed every second (in my C program) and instead of my gui displaying a new message every second, it displays all of them after 5 seconds (max number of iterations).

So is there a way to know exactly when new messages are available for reading and updating the gui accordingly?

Here is the relevant piece of the C program:

int loopcount = 0;
while (loopcount<5) {
    printf("loop #%d\n", loopcount);
    loopcount++;
    Sleep(1000);
}
incantation
  • 13
  • 1
  • 6
  • show your c program – eyllanesc Mar 08 '19 at 15:57
  • I've added the test part of the C program – incantation Mar 08 '19 at 16:04
  • add `fflush(stdout);` after of `printf` – eyllanesc Mar 08 '19 at 16:26
  • I'm not sure I understand -- you have a C program that produces some output, and another program (using Qt) to display that output? Your second alternative looks better than the first, though I'd encourage you to use the newer syntax for connect() calls. You may somehow be blocking your event loop -- one way to tell is to use qDebug()calls in the slot that reads the stdout from the other program. – mzimmers Mar 08 '19 at 16:31
  • @eyllanesc this was it, works like a charm now. Thank you very much! – incantation Mar 08 '19 at 16:34

0 Answers0