QTimer, start, stop and start again



  • Hello,

    I have a QTimer that repeatedly runs a function. I start it with an interval of 20 ms. Later I stop it. Then I start it again with the same interval of 20 ms. After that, I realize that the function is called twice as much as it was before I stopped the QTimer for the first time. If I stop and start it again, then the function will be called thrice as much.

    It looks like QTimer::stop doesn't do what I hoped it would. How exactly can I stop a QTimer from running a function for some time, then make it resume with the same interval ?


  • Lifetime Qt Champion

    Hi,

    Can you share the code you use to start and stop your QTimer ?

    If it's called twice as much after a single stop/start sequence, it might be that you're connecting again your QTimer object to your slot.



  • @SGaist said:

    it might be that you're connecting again your QTimer object to your slot.

    That's exactly what I was doing! Thanks a lot, everything works perfectly now.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.