wxTimer doesn't fire up when using Bind to connect the timer

52 views
Skip to first unread message

Sean Mayard

unread,
Jun 18, 2022, 3:55:06 AM6/18/22
to wx-u...@googlegroups.com
I am using wxTimer and i noticed that if i use the following, everything(the timer) works/fires up correctly:

timer = new wxTimer(this);
Bind(wxEVT_TIMER, &MyPanel::onTimer, this, timer->GetId());

But when i use timer->Bind as shown below the timer doesn't fire up.

timer = new wxTimer(this);
timer->Bind(wxEVT_TIMER, &MyPanel::onTimer, this);

Note in the latter the id of the timer is not passed as an argument because i thought that since we are explicitly binging the timer using timer->Bind so we don't need to pass the id.

My question is how is that the second case doesn't work. I read here that when we don't use SetOwner  then we must use Connect/Bind. But that's what I did and still the second case is not working. Why/how is that?

Vadim Zeitlin

unread,
Jun 18, 2022, 9:33:39 AM6/18/22
to wx-u...@googlegroups.com
On Sat, 18 Jun 2022 13:24:51 +0530 Sean Mayard wrote:

SM> I am using wxTimer and i noticed that if i use the following, everything(the timer) works/fires up correctly:
SM> timer = new wxTimer(this);
SM>
SM> Bind(wxEVT_TIMER, &MyPanel::onTimer, this, timer->GetId());
SM> But when i use timer->Bind as shown below the timer doesn't fire up.
SM> timer = new wxTimer(this);
SM> timer->Bind(wxEVT_TIMER, &MyPanel::onTimer, this);
SM>
SM> Note in the latter the id of the timer is not passed as an argument
SM> because i thought that since we are explicitly binging the timer using
SM> timer->Bind so we don't need to pass the id.
SM> My question is how is that the second case doesn't work. I read here
SM> that when we don't use SetOwner then we must use Connect/Bind. But
SM> that's what I did and still the second case is not working. Why/how is
SM> that?

You did set the timer owner by passing "this" to its ctor. For the timer
itself to get its own events, you need to use its default ctor.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
Reply all
Reply to author
Forward
0 new messages