how to make QProcess waiting for response....
-
myMainWindow.h private: bool readStdOutput(QString myrightstring) if (myprocess->readallstandardoutput().simplified == myrightstring) { return true; } else { return false; ] .......... myMainWindows.cpp connect(this,SIGNAL(myqString(QString), ui.mylabel,SLOT(settext(QString))); void myMainWindows::myQprocessWrite() { myqprocess->write("mycommand"); myqprocess->waitforfinisced(200); <---------------------the time of response is really max 5000 myqprocess->write("get my response to mycommand"); myqprocess->waitforfinisced(200); if (readStdOutput("my supposed right response")){ emit myqString("hello world");} else {myotherworks();} } void myMainWindows::myotherworks() { myQprocessWrite() ]
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
regards
Giorgio -
Hi,
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 ....
regards
Giorgio -
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?
-