Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to delay QTimer start?
Forum Updated to NodeBB v4.3 + New Features

How to delay QTimer start?

Scheduled Pinned Locked Moved Solved Qt for Python
3 Posts 3 Posters 1.4k 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.
  • A Offline
    A Offline
    ACollins
    wrote on last edited by
    #1

    I have the QTimer working with proper connect and interval of 1-minute. I would like for it to start at the top of the minute, i.e. when the time has 0 seconds, so that it will be called every minute on time such at 9:31, 9:32:00, 9:33:00..... If the program starts at 9:30:43 for example I want the timer to start at 9:31:00. Is there a simple way to do this?

    The only way I can think of is to fire a single shot timer which waits till 9:31:00 in the above example to start the 1-minute timer. Thanks.

    JonBJ 1 Reply Last reply
    0
    • A ACollins

      I have the QTimer working with proper connect and interval of 1-minute. I would like for it to start at the top of the minute, i.e. when the time has 0 seconds, so that it will be called every minute on time such at 9:31, 9:32:00, 9:33:00..... If the program starts at 9:30:43 for example I want the timer to start at 9:31:00. Is there a simple way to do this?

      The only way I can think of is to fire a single shot timer which waits till 9:31:00 in the above example to start the 1-minute timer. Thanks.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @ACollins
      Yes, the initial singleshot to delay when it starts till the minute arrives is the usual way.

      Note also the following about accuracy. I imagine that, once started, you intend the timer to keep expiring on the minute for an extended period of time. However, timers can expire late, or even early. Read https://doc.qt.io/qt-5/qtimer.html#accuracy-and-timer-resolution. The default QTimer is https://doc.qt.io/qt-5/qt.html#TimerType-enum

      Qt::CoarseTimer 1 Coarse timers try to keep accuracy within 5% of the desired interval

      You might want to improve to Qt::PreciseTimer (though I'm not sure that is intended for this kind of job).

      I am unsure whether an early/late expiry is "cumulative", i.e. the next timer interval starts from when it did expire, rather than when it should have expired. If it's the former then your timeout can "wander" over time.

      I think you'd have to try it setting it off for a day, with the computer doing various things, to discover. If it does wander unexpectedly, I imagine the approach is: set the timer repeating interval, in the timeout check the system clock, if it has wandered too far stop the timer and correct for next interval and restart, repeating this adjustment at next interval till it settles down to close enough again.

      Finally, if you have that last part you can probably use it to avoid the initial singleshot of your question: you could set the first timer to 17 seconds ( 9:30:43 -> 9:31:00), for example, and allow it to "correct" on first expiry.

      1 Reply Last reply
      0
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @JonB said in How to delay QTimer start?:

        I am unsure whether an early/late expiry is "cumulative", i.e. the next timer interval starts from when it did expire, rather than when it should have expired. If it's the former then your timeout can "wander" over time.

        It's not :)

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        2

        • Login

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