Hello,

I would like to execute a function on a Windows machine as close to every 12 ms as somehow possible. Right now I'm using a QTimer and I'm not sure how well it does the job. The following test setup:

Qt Code:
  1. constructor
  2. {
  3. stepTimer = new QTimer(this);
  4. connect(stepTimer,SIGNAL(timeout()), this, SLOT(tick()));
  5. stepTimer->start(12);
  6.  
  7. time = new QTime();
  8. time->start();
  9. }
  10.  
  11. void tick()
  12. {
  13. qDebug() << time->restart();
  14. }
To copy to clipboard, switch view to plain text mode 

shows that the tick() function is executed every 15 or 16 milliseconds. The output is like:

15,16,15,16,15,16,15,16,15,16,15,16,15,16....

When I start the timer with 10 ms instead of 12, I get:

0,16,15,0,16,15,0,16,15,0,16,15,0,16,15...

This is not exactly satisfactory.


First of all, how exact are the timings that QTime::restart() is showing me?

Of course it's very clear that tick() should execute in less than 12 ms and I believe qDebug() does so, but I better ask than be wrong?

I know that Windows is not a real time OS and my own experiments show that it delivers a precision somewhere around the 10 ms mark. Does anyone have more exact information?

And last but not least, what can I do to get the 12 ms rhythm as steady as possible?