Results 1 to 4 of 4

Thread: QTime stop delay

  1. #1
    Join Date
    Aug 2012
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTime stop delay

    How to give a stop delay for delay processing in loop execution using QTime in qt?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QTime stop delay

    Why you want to use QTime. If have decided to do so, write a while/for loop to monitor the time and count the delay you want.

    One could use QThread::sleep() also
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Aug 2012
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTime stop delay

    QTime dieTime= QTime::currentTime().addMSecs(10);
    while( QTime::currentTime() < dieTime )
    QCoreApplication:rocessEvents(QEventLoop::AllEvents, 100);

    I used this code for delay processing in my project.but I don't know how to stop this delay processing in loop execution?

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTime stop delay

    Quote Originally Posted by sangee View Post
    QTime dieTime= QTime::currentTime().addMSecs(10);
    while( QTime::currentTime() < dieTime )
    QCoreApplication:rocessEvents(QEventLoop::AllEvents, 100);

    I used this code for delay processing in my project.but I don't know how to stop this delay processing in loop execution?
    And when the time changes from summer to winter you wait an hour. For this type of calculation, use QElapsedTimer which is insensitive to change the clock settings on your computer. A more elegant solution :
    Qt Code:
    1. QEventLoop my_loop;
    2. QTimer::singleShot( how_long_ms,&my_loop,SLOT(quit()) );
    3. loop.exec();
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QTime
    By dragon in forum Newbie
    Replies: 12
    Last Post: 16th February 2012, 10:40
  2. Help me qtime in qt?
    By tamnv110 in forum Newbie
    Replies: 7
    Last Post: 16th June 2011, 11:59
  3. QTime error?
    By roxton in forum Qt Programming
    Replies: 2
    Last Post: 19th October 2010, 22:06
  4. QTime
    By bismitapadhy in forum Qt Programming
    Replies: 1
    Last Post: 26th June 2009, 05:21
  5. QTime restart
    By jhowland in forum Qt Programming
    Replies: 1
    Last Post: 8th October 2008, 20:18

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.