Results 1 to 4 of 4

Thread: Asynchronous loop with QStateMachine

  1. #1
    Join Date
    May 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Asynchronous loop with QStateMachine

    Hi all,

    I am new guy using a Qt. I am developing a HW testing SW (GUI) with Qt.
    I need to develop a statemachine which has four states: stopped, running and paused.
    On the mainwindow there are eight widgets which represents the components to be tested. User can enter test parameters for each of the eight component.
    The main problem is that when statemachine goes to running state I need to loop in the switch case method (running state == switch case method) I have one case for each of the HW component to be tested.
    Test procedure:
    Start state-> (button pressed) -> Test component1->break from the switch case->loop back to switch case->test component2->break and so on until component8 is tested. When user presses Stop button statemachine goes to stopped state. I can manage all this by creating a simple switch case structure but the problem is that the loop is synchronous and user actions on the GUI are disabled (User can not stop the loop by pressing Stop button). So How to develop a asynchronous loop with QStateMachine? Thanks for a help!
    Last edited by wysota; 31st May 2011 at 11:58.

  2. #2
    Join Date
    Aug 2008
    Posts
    45
    Thanks
    1
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Asynchronous loop with QStateMachine

    I think you should think this a bit differently.
    Do those component tests block the execution when they are run? If they do then you should do something to turn each of those tests into asynchronous calls instead of synchronous, so that they will not block main thread and freeze GUI.
    like:
    Qt Code:
    1. void StateMachine::doTests() {
    2. ...
    3. case TestComponent1:
    4. testComponent1->start(); // returns immediately, doesn't wait for the execution to start
    5. ...
    6. }
    7.  
    8. void StateMachine::onTestComponent1Finished() { // this slot is connected to testComponent1's signal finished()
    9. if( false == isStopped )
    10. {
    11. doTests(); // execute next test
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    When you click the stop-button in GUI you can just set the isStopped to true and the execution should stop when currently running test has finished.

  3. #3
    Join Date
    Feb 2006
    Location
    Denmark
    Posts
    11
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Asynchronous loop with QStateMachine

    You can put in a call to

    Qt Code:
    1. QEventLoop::ProcessEvents(...)
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    May 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Asynchronous loop with QStateMachine

    Calling qApp->ProcessEvents(); did the trick. Thanks.

Similar Threads

  1. Main loop thread loop communication
    By mcsahin in forum Qt Programming
    Replies: 7
    Last Post: 25th January 2011, 16:31
  2. Aid on QStateMachine
    By giorgik in forum Qt Programming
    Replies: 1
    Last Post: 27th April 2010, 10:24
  3. QStateMachine
    By piotr.dobrogost in forum Qt Programming
    Replies: 3
    Last Post: 6th December 2009, 08:17
  4. QStateMachine, not getting entered()
    By jimiq in forum Qt Programming
    Replies: 10
    Last Post: 19th November 2009, 10:17
  5. QStateMachine and signals
    By rossm in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2009, 10:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.