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. Is this possible to loop more than one function using one timer?
QtWS25 Last Chance

Is this possible to loop more than one function using one timer?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 271 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.
  • B Offline
    B Offline
    BD9a
    wrote on last edited by
    #1

    I want to have ~3 looped functions, each with diffrent interval / sleep time. I want to call them in same time (when time to execute first function going down it also going down for other functions too). Is this possible?

    Graphic example
    alt text

    1 Reply Last reply
    0
    • JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      Why not 3 timers calling the 3 functions with intervals as shown?

      1 Reply Last reply
      3
      • B Offline
        B Offline
        BD9a
        wrote on last edited by
        #3

        Thinking about it, and it should work in my case. But what when I want to call more functions? Will it have big impact to performance?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          A timer only times out for a given interval. So as @JonB wrote, you need three timers.

          As for the performance, it will depend on what your functions do and how fast they do it.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • Kent-DorfmanK Offline
            Kent-DorfmanK Offline
            Kent-Dorfman
            wrote on last edited by Kent-Dorfman
            #5

            this is a simple task and common when there are few timers available. set a time interval as the lcd (least common denominator) of the needed period, then in the timer service routine count how many times the timer expired and call the correct function in a conditional statement.

            In your case interval is 1sec.
            on 2 expirations execute function1
            on 3 expirations execute function2
            on 4 expirations execute both 2 and 4 (or just 4 if that's your intention)

            And you probably would not want to directly call the functions, but instead emit signals from the timer service routine.

            1 Reply Last reply
            1

            • Login

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