PDA

View Full Version : QTime stop delay



sangee
27th October 2012, 14:25
How to give a stop delay for delay processing in loop execution using QTime in qt?

Santosh Reddy
29th October 2012, 05:37
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

sangee
29th October 2012, 14:08
QTime dieTime= QTime::currentTime().addMSecs(10);
while( QTime::currentTime() < dieTime )
QCoreApplication::processEvents(QEventLoop::AllEve nts, 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?

Lesiok
29th October 2012, 15:04
QTime dieTime= QTime::currentTime().addMSecs(10);
while( QTime::currentTime() < dieTime )
QCoreApplication::processEvents(QEventLoop::AllEve nts, 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 :
QEventLoop my_loop;
QTimer::singleShot( how_long_ms,&my_loop,SLOT(quit()) );
loop.exec();