Connect two events to one derived class

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
oarzu
In need of some credit
In need of some credit
Posts: 4
Joined: Fri Mar 20, 2009 3:49 pm
Location: El Segundo

Connect two events to one derived class

Post by oarzu »

I have a class rtnSWITCH that is derived from the wxSlider class. In rtnSWITCH i've connected two events to the class.

Code: Select all

	Connect(id, wxEVT_LEFT_DOWN, wxMouseEventHandler(rtnSWITCH::OnLeftClick));
	Connect(id, wxEVT_COMMAND_SLIDER_UPDATED, wxCommandEventHandler(mcuFrame::OnLaser));
The second eventhandler points to a member function of a different class.

Only the first event works. What i want my class to do: First event(left-click) changes the slider value , second event(slider-updated) points to a function that will change a corresponding wxStaticBitmap accordingly.

Does any know why the second event never happens?

Thanks in advance.
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: Connect two events to one derived class

Post by catalin »

oarzu wrote:

Code: Select all

Connect(id, wxEVT_COMMAND_SLIDER_UPDATED, wxCommandEventHandler(mcuFrame::OnLaser));
[...] points to a member function of a different class.
Rewrite that call like this:

Code: Select all

Connect(id, wxEVT_COMMAND_SLIDER_UPDATED, wxCommandEventHandler(mcuFrame::OnLaser), NULL, pointerToAnInstanceOf_mcuFrame);
The connection is not to a class, but to an instance - an actual object, which is implicitly "this", otherwise needs to be specified.
You need to specify the eventSink, that is the actual object that has the event handler (OnLaser) as a member; see the last parameter of wxEvtHandler::Connect
oarzu
In need of some credit
In need of some credit
Posts: 4
Joined: Fri Mar 20, 2009 3:49 pm
Location: El Segundo

Post by oarzu »

The instance of mcuFrame is the object that is using the rtnSWTICH class. My mcuFrame class has multiply instances of rtnSWITCH. I want each instance to be connected to the left-click event and perform the same operation to that instance. Easily done by adding the first Connect statement. Now in the mcuFrame class when each instance of the rtnSWITCH changes because of the left-click event, I want another action to be taken because of the change. I first tried connecting each instance of the rtnSWITCH to a SLIDER_UPDATED event. The second event was never executed, hence trying to put both connects into the rtnSWTICH class.
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Post by catalin »

Unfortunately I do not understand what is "not working" in your code, but just a hunch: you may need to use event.Skip() in your handlers (wxEvent::Skip).
Post Reply