Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTimer Accuracy for Qt::PreciseTimer
QtWS25 Last Chance

QTimer Accuracy for Qt::PreciseTimer

Scheduled Pinned Locked Moved Solved General and Desktop
qtimer
2 Posts 2 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pandako
    wrote on 29 Jul 2022, 03:17 last edited by
    #1

    Hello, I used a QTimer to fetch real-time data. I know that the resolution is 1ms for Qt::PreciseTimer, and I just test this on my machine.

    connect(mytimer, &QTimer::timeout, this, &MyClass::onTimeOut);
    mytimer->setInterval(20);
    mytimer->setTimerType(Qt::PreciseTimer);
    mytimer->start();
    

    For Windows machine , I use QueryPerformanceFrequency and QueryPerformanceCounter to record time intervals. And for Linux machine, I use gettimeofday.

    I draw a plot for the recorded time intervals as the following plot. The y axis is the time, and the unit is ms. The x axis is the number of time intervals. For most time, I can see the time interval falls between 19ms and 21ms.
    But it exceeds 21ms or runs below 19ms sometimes, I was wondering, if someone would give me a hint about why this occurs?

    778a19b3-3e5d-4820-abb6-1d1872a7f704-image.png

    The above plot is the test on Windows. But I could observe similar thing on Linux machine. Could someone tell me why QTimer would be not accurate sometimes? Is this related to system's task dispatch rules or anything else?

    Thank you!!!

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JKSH
      Moderators
      wrote on 29 Jul 2022, 04:58 last edited by JKSH
      #2

      @Pandako said in QTimer Accuracy for Qt::PreciseTimer:

      But it exceeds 21ms or runs below 19ms sometimes, I was wondering, if someone would give me a hint about why this occurs?

      This is called "jitter".

      Windows is definitely not a real-time operating system (RTOS), and most Linux machines aren't either. This means the OS does not guarantee that your timers will always meet the intervals that you specify.

      If you truly need deterministic timers which guarantee that jitter levels are always below a certain threshold, then you need an RTOS.

      • Qt officially supports a few commercial RTOS'es: INTEGRITY, VxWorks, and QNX
      • Ubuntu also recently announced a beta version of a real-time kernel: https://ubuntu.com/engage/an-introduction-to-real-time-linux-part-i

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      2

      2/2

      29 Jul 2022, 04:58

      • Login

      • Login or register to search.
      2 out of 2
      • First post
        2/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved