Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to make QProcess waiting for response....
Forum Updated to NodeBB v4.3 + New Features

how to make QProcess waiting for response....

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 2.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • gfxxG Offline
    gfxxG Offline
    gfxx
    wrote on last edited by
    #1
    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

    bkt

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • gfxxG Offline
        gfxxG Offline
        gfxx
        wrote on last edited by
        #3

        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

        bkt

        1 Reply Last reply
        0
        • jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • gfxxG Offline
            gfxxG Offline
            gfxx
            wrote on last edited by gfxx
            #5

            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?

            bkt

            mrjjM 1 Reply Last reply
            0
            • gfxxG gfxx

              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?

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @gfxx

              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

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved