I have been trying to connect my timer to an a function. In my derived class What i am doing is
Timer->SetOwner(this,wxID_Timer);
Timer->Connect(wxID_Timer,wxTimerEventHandler( Window::OnUpdate ), NULL, this );
Where my declaration of OnUpdate is
void OnUpdate( wxTimerEvent& event );
Can any one tell me what is wrong here, why is OnUpdate not being called periodically after i start the timer?. Please and Thank you.
Also I am not using static event Tables.The other answer on wxTimer is not helping me.
After a bit of searching i actually found the answer, no one is answering so i am posting it here. There were a few things that i was doing wrong. i. I actually had to connect the class to my timer . That meant i had to do something like
this->Connect(Timer.GetId(),wxEVT_TIMER,wxTimerEventHandler( Window::OnUpdate ), NULL, this );
Where wxEVT_TIMER was the event type.
Similarly to disconnect
this->Disconnect(wxID_Timer,wxEVT_TIMER,wxTimerEventHandler( Window::OnUpdate ), NULL, this );
There seems to be some confusion here so let me try to clear it.
You can either call timer->Connect(...)
on the timer itself or use SetOwner(frame)
and then do frame->Connect(...)
.
Calling SetOwner()
and then calling Connect()
on the timer doesn't make much sense as SetOwner()
ensures that the timer event is delivered to the owner directly. However by default there is no owner and the timer sends the events to itself which is why without SetOwner()
call you must call Connect()
on the timer.
The answer did not work for me. This is what I did instead.
You first must let your frame own the events that the wxtimer emits.
m_timer.SetOwner( this );
Then you can have your frame's event handler handle the events. If you only have one timer, use this.
this->Connect( wxEVT_TIMER, wxTimerEventHandler( Frame::OnTimer ), NULL, this );
If you have multiple timers, use this to connect each timer's event to a different function.
this->Connect( m_timer.GetId(), wxEVT_TIMER, wxTimerEventHandler( Frame::OnTimerForSpecificTimer ), NULL, this );
Doing this will allow the frame to put the timer event in its event queue and process it when it can.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With