Results 1 to 4 of 4

Thread: How to wait 2 seconds before continue

  1. #1
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Red face How to wait 2 seconds before continue

    Hi everybody,

    how could i wait 2 seconds one my code before i continue?

    I know that with QTimer its possible, but i need a example..

    Can somebody send me a example?
    Think DigitalGasoline

  2. #2
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to wait 2 seconds before continue

    1. Create QTimer
    2. connect QTimer's signal (timeout) to your slot
    3. start it

    Qt Code:
    1. QTimer *timer = new QTimer;
    2. timer->setSingleShot(true);
    3.  
    4. connect(timer, SIGNAL(timeout()), this, SLOT(yourSlot()));
    5.  
    6. timer->start(2000);
    7.  
    8. ...
    9.  
    10. void yourClass::yourSlot()
    11. {
    12.  
    13. }
    To copy to clipboard, switch view to plain text mode 

    or maybe you just want to do sleep(2). I don't the reasons why you need to wait.
    I'm a rebel in the S.D.G.

  3. #3
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to wait 2 seconds before continue

    Thanks it works!!!

    Think DigitalGasoline

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to wait 2 seconds before continue

    Btw, QTimer has a convenient static method which can combine all that to a single statement:
    Qt Code:
    1. QTimer::singleShot(2000, this, SLOT(yourSlot()));
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

Similar Threads

  1. How to make my program wait for 2 seconds ?
    By probine in forum Qt Programming
    Replies: 2
    Last Post: 26th December 2006, 14:31

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.