how to make QProcess waiting for response....

  • myMainWindow.h
    bool readStdOutput(QString myrightstring)
       if (myprocess->readallstandardoutput().simplified  == myrightstring)
    return true;
    return false;
    connect(this,SIGNAL(myqString(QString), ui.mylabel,SLOT(settext(QString)));
    void myMainWindows::myQprocessWrite()
        myqprocess->waitforfinisced(200);    <---------------------the  time of response is really max 5000
        myqprocess->write("get my response to mycommand");
        if (readStdOutput("my supposed right response")){ emit myqString("hello world");}
        else {myotherworks();}
    void myMainWindows::myotherworks()

    my QpROCESS START CORRECTLY AT THE top of mymainwindowGui ..... but if myotherworks() is call the gui become not responsive and freeze.....

    other problem ..... waitforfinisced(200); is ok but 5000 make gui not responsive..... if run QProcess (aND myQprocessWrite() aND myotherworks()) in a qTHREAd the gui become responsive ..... but mylabel update but not at correct time .... with qprocess in qthread i use quequedconnection but I try direct too..... without success.....

    Any suggest is appreciated


  • Lifetime Qt Champion


    Why do you need to wait for that ? You could take advantage of the asynchronous nature of QProcess to avoid that lock.

  • I need to wait the response because from the response depends on the next sequence of commands ...... if bringh async response I will not be able to connect the unit to the response. The response can be immadiate (5msec) or can be late up to 5sec (5000msec) .... I can help but to wait as long to create a command table and to compare asynchronous responses with that to figure out what's going on ..... it seems to me something which in itself is subject to errors ....

    You have another ideas?? ....

    to be more precise I would need a sequence of commands sent with myprok-> write and relative reply ....


  • Moderators

    You're actually describing a prefect example for asynchronous programming.
    You just need a state variable where you store the last action you executed. If you get the response again you check that variable and execute the next command and change the status variable accordingly.

  • I'm not shure if is my preferred solution .... but you made me think about a different way of approaching the problem ..... I think I'll do that .... I will not make anything happen in MainWindow so long as myprocess / stdout has not returned to me an answer then I will compare with the state variable .... simply stop being on hold and in the meantime I do a setenable (false) button / buttons in the gui that launches / launch command ..... or ....

    I can make a setenable (true) of all the gui with one command?

  • Qt Champions 2016


    I can make a setenable (true) of all the gui with one command?

    You can easy get a list of all widgets
    QList<QPushButton*> mylist = mainwin->findChildren<QPushButton*>();
    then loop over list and call setEnabled

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.