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. Experience with QTimer and long time spans
Forum Updated to NodeBB v4.3 + New Features

Experience with QTimer and long time spans

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 5.1k Views 1 Watching
  • 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.
  • G Offline
    G Offline
    gandiii
    wrote on last edited by
    #1

    Hello,

    I need three timers for some actions in a time span
    between days and weeks.
    Is it possible or does it make sense, to take a singleshot timer
    and set the timespan I need. Or should I use counters and one
    timer with minute or hour clock?
    I have to pay attention on the memory usage, because
    this is an embedded system

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DerManu
      wrote on last edited by
      #2

      How about this: Set a timer to an interval of, say, 10 Minutes (or even an hour when you don't need such fine grained control). In the timeout() slot, you check whether QDateTime::currentDateTime() is greater than a QDateTime that you've set up to point at the desired time in the future. If this is the case, execute whatever you need.

      If you want a more sophisticated and flexible approach, make an abstract functor class and a QMap<QDateTime, AbstractFunctor>. In the timer slot, iterate through the map from the beginning until the map key is greater than the currentDateTime, execute and then remove the functors from the map. This way your future events can even survive program/system shutdown without trouble by saving the map in a destructor/closeEvent.
      When adding new events, create the desired functor subclass, set any state parameters that shall define the behaviour at the event, and add it to the map.
      Tip: in the timer slot, set the timer interval to the maximum of ~1h and the difference of the current time to the next event. This way you have persistent, exact timing for multiple events without the need for multiple timers with huge intervals.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        Do you actually know your application is going to run for this time?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          gandiii
          wrote on last edited by
          #4

          @DerManu: thank you for your answer, I hope I have understood, what you meant.
          @Andre: this application should be a controller for a weather station and should run "endless".

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DerManu
            wrote on last edited by
            #5

            [quote author="gandiii" date="1336748880"]this application should be a controller for a weather station and should run "endless".[/quote]
            Oh that's nice. Our measurement stations (not weather though) have crashed regularly in the first years of development. Do you plan to implement remote firmware/software updates? If not, happy hiking with a screwdriver every evening ;). If yes, good, then you'll need persistent timed events, though.

            1 Reply Last reply
            0

            • Login

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