Important: Please read the Qt Code of Conduct -

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

  • 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

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

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

  • 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?

  • Lifetime Qt Champion


    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.

  • 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.

Log in to reply