Q timer Event with timer id
-
Dear sir,
I want to implement a continuous calling for a function from Q Timer::timer Event(QTimerEvent *e) by creating a timer event using QTimerEvent::QTimerEvent(int timerId) that calls a function continuous in a specific time.
so please help me to create a timer event for continuous calling of a particular function. -
@qt_ankit_developer said in Q timer Event with timer id:
to create a timer event for continuous calling of a particular function.
Why do you want it to be a QTimerEvent?
It's easier to just use QTimer and connect it to a slot.
-
Dear sir,
I want to implement a continuous calling for a function from Q Timer::timer Event(QTimerEvent *e) by creating a timer event using QTimerEvent::QTimerEvent(int timerId) that calls a function continuous in a specific time.
so please help me to create a timer event for continuous calling of a particular function.@qt_ankit_developer
even so @sierdzio is correct, a QTimer instance would be easier. Here is how you would do it via QTimerEvent:void myClass::startMyTimerEvent() { if (m_timerId == -1) m_timerId = startTimer(m_Timeout); } void myClass:: stopMyTimerEvent() { if (m_timerId != -1) killTimer(m_timerId); m_timerId = -1; } void myClass::timerEvent(QTimerEvent *event) { if(event->timerId() == m_timerId) { //do Stufff .... callMyFunction(); } }
-
how can i call different event with different timer ids
-
There is nothing like calling different event with different timer ids. As @J-Hilk suggested with example, you start multiple timers. Each timer started will have timer ids. When the timer expires, it will call handler timerEvent(...). Inside the handler you need to check the appropriate timerIds and call the different eventHandler based on your requirement.
As @sierdzio suggested, you can consider using QTimer itself.
-
Hi,
You can build a map with the timer ids and method to call and use that in
timerEvent
to call the right function.However, a list of QTimer might be easier to handle.