PDA

View Full Version : Qt5 / C++ - Time delay, Windows 10 - Windows 7



jimbo
31st May 2016, 09:36
QT 5.6.0

Hello,

I'm using a time delay in my program, and noticed a drastic difference
in execution time between Windows 10 and Windows 7 (Dual boot system).
The time delay does not have to accurate (Animation).

Typical output:-
15156535 Windows 10
1379155 Windows 7

Its probably the processEvents, I would like the system to be responsive.
Is there a better way to achive similar results between the two systems?

Regards


void myProg:tDelay(int milliSecs)
{
QElapsedTimer timer;
timer.restart();
qint64 nanoSec;
timer.start();

QTime dieTime = QTime::currentTime().addMSecs(milliSecs);
while (QTime::currentTime() < dieTime)
QCoreApplication::processEvents(QEventLoop::AllEve nts, 1);

nanoSec = timer.nsecsElapsed();
qDebug() << nanoSec;
}

anda_skoa
31st May 2016, 11:49
QTime::currentTime can be a very costly call.

But maybe you can explain what you are actually trying to do?
That doesn't look like anything that would appear in a real program.

Cheers,
_

jimbo
31st May 2016, 12:54
Hello anda_skoa,

Thanks for your reply.
I'm doing nothing more than moving a QLabel around a form, with the delay between moves.

Regards

anda_skoa
31st May 2016, 13:06
Hmm.

Wouldn't that be easier with a QPropertyAnimation?

Cheers,
_

Lesiok
31st May 2016, 14:24
If You really need this method do it like this :
void myProg:tDelay(int milliSecs)
{
QElapsedTimer timer;
timer.restart();
qint64 nanoSec;
timer.start();
QEventLoop loop;
QTimer::singleShot( milliSecs,&loop,SLOT(quit()) );
loop.exec();

nanoSec = timer.nsecsElapsed();
qDebug() << nanoSec;
}

jimbo
2nd June 2016, 09:00
Helo,

Thanks to anda_skoa and Lesiok.


Wouldn't that be easier with a QPropertyAnimation?
Yes, some nice effects.


If You really need this method do it like this :
Gives a simiar result between the two systems.

Regards