Results 1 to 4 of 4

Thread: I need a pause (QTimer)

  1. #1
    Join Date
    Aug 2007
    Posts
    274
    Thanks
    27
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default I need a pause (QTimer)

    Hi guys i am trying to interface into a system which needs pause (wait for some time in every command). eg
    signature function will do the following


    send enable command

    pause for some time

    send signature request
    pause for sometime
    send signature request for another device
    can i use a QTimer to create a wait inside my function? Is this possible?

    baray98

  2. #2
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: I need a pause (QTimer)

    Quote Originally Posted by baray98 View Post
    Hi guys i am trying to interface into a system which needs pause (wait for some time in every command). eg


    can i use a QTimer to create a wait inside my function? Is this possible?

    baray98
    If the command sending function is a single function which accepts string or predefined set of parameters, then probably you can use a Queue something like this.

    Qt Code:
    1. QQueue<QString> q;
    2.  
    3. sendSignature()
    4. {
    5. q.clear(); //clear pending jobs
    6. q << "enable" << "sigrequest1" << "sigrequest2" ..;
    7.  
    8. sendCommands();
    9. }
    10.  
    11. sendCommands()
    12. {
    13. if(q.isEmpty())
    14. return;
    15. act_sendCommand(q.head()); //this is the function responsible to send the command
    16. q.dequeue();
    17. QTimer::singleShot(delay, this, SLOT(sendCommands())); //call self to call subsequent commands
    18. }
    To copy to clipboard, switch view to plain text mode 

    Ofcourse this system might fail if you are using multiple threads..
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  3. #3
    Join Date
    Aug 2007
    Posts
    274
    Thanks
    27
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: I need a pause (QTimer)

    Good, that might work for me i dont have multiple threads i tried to make my life simple...
    Any more ways gentlemen

    baray98

  4. #4
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: I need a pause (QTimer)

    If you aren't using multiple thread and if you can assure no reentrancy then there is chance that this following method will also work for you
    Again stressing the fact that this will fail miserably if there is chance of you calling the manualPause function while it is already in progress.
    Probably you can disable the buttons/control widgets when the manualPause is in progress. (also function using manualPause won't be reentrant)

    Qt Code:
    1. enum State
    2. {
    3. Paused,
    4. Run
    5. };
    6.  
    7. State state;
    8.  
    9. /** This function won't return till the time delay */
    10. void manualPause()
    11. {
    12. state = Paused;
    13. QTimer::singleShot(delay, this, SLOT(setRunState());
    14. while(1) {
    15. qApp->processEvents();
    16. if(state == Run) break;
    17. }
    18. }
    19.  
    20. void setRunState()
    21. {
    22. state = Run;
    23. }
    To copy to clipboard, switch view to plain text mode 
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  5. The following user says thank you to Gopala Krishna for this useful post:

    baray98 (17th January 2008)

Similar Threads

  1. Replies: 1
    Last Post: 14th June 2007, 15:52
  2. QTimer single shot and too busy app.
    By Pier in forum Qt Programming
    Replies: 3
    Last Post: 20th March 2007, 14:02
  3. Replies: 5
    Last Post: 6th March 2007, 05:34
  4. using QTimer in staticlib
    By jeetu_happy in forum Qt Programming
    Replies: 4
    Last Post: 22nd January 2007, 09:34
  5. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54

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.