⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

Is it worth to start and stop QTimer ?

  • I am using QTimer of pyside library in my code.
    I have QT application containing items in listwidget and tabwidget having 3 tabs(0, 1, 2).

    I have to update some value on "tab 1" periodically (periodicity will depend on item selected)

    What i am doing:
    I wrote a callback for updating value on "tab 1".
    Created timer initially and connected callback to it.
    Starting timer when "tab 1" is clicked for 1st time and timeout will depend on selected item in listwidget

    I thought of two cases of doing it:
    if "tab 1" is selected and start timer is not alive:

    1. whenever an item is selected stop the timer and again start it with new timeout (of selected item)
    2. change timeout of timer and no need to stop and start it.

    if "tab 0" and "tab 2" selected:
    stop timer

    I need to take a decision on which method to use when "tab 1" is selected.

    I prefer 2nd method but on QTimer documentation i read that changing timeout will change timerID. I don't know how much this affects or adds overhead.

    Please give your views about these 2 methods and Which method is technically good ?

  • Lifetime Qt Champion


    The question is: are you using the timer id at any point in your code ? If not then just update the interval

  • I am not using timer id in code.
    But i want ot know technical (or internal or in terms of overhead) differences between those 2 methods.

  • Lifetime Qt Champion

    Then you should take a look directly in QTimer's sources

Log in to reply