Important: Please read the Qt Code of Conduct -

New to Qt, could use some help with Qprocess

  • 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 << "";
            stdoutput->append("<h1><font color=red>There was a problem starting the software, please try running the program again.</font></h1>");

    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();
    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?

    here is the code from the program:

    @int main(int argC[], char* argV[]){
    char* input = malloc(160);

    while(strcmp(input,"quit") != 0)
        printf("Got input %sn", input);


    I also noticed that if I call close on the Qprocess, I wont read anything, it's only when I send the program the "quit" message

  • Normally, stdout is buffered. So you should


    in your test program after printf'ing the input.

    You might also have a look at Qt's "QTextStream": and "QDataStream": classes for the io.

  • Ahh, Thanks a lot.

    I thought c flushed output on a newline, I guess I am mistaken.

    I appreciate the help a ton! This has been bothering me for a while.

  • stdout is line buffered if attached to a terminal, block buffered else.

Log in to reply