How to call a function periodically in Qt?

后端 未结 5 1276
耶瑟儿~
耶瑟儿~ 2021-02-14 22:10

Is it possible to call a function periodically in C++ with Qt function ?
And how to stop the timed function after it is set to be called periodically ?

5条回答
  •  遇见更好的自我
    2021-02-14 23:14

    You can use the QTimer class.

    Just declare a QTimer with the desired time interval, wrap your function in a QObject as a slot, and connect the QTimer's timeout() signal to the slot you just declared.

    Then, when the condition for stopping calling the function is met, just call QTimer::stop().

提交回复
热议问题