views:

20

answers:

1

I appear to have followed this example (found under "Defining Your Own Event Class"), and my code compiles and runs without error, but I'm not catching the event anywhere.

The code:

class MyCustomEvent : public wxEvent
{
//... stuff here
};
wxDEFINE_EVENT(MY_CUSTOM_EVENT_1,MyCustomEvent);

and later I bind the event:

Bind(MY_CUSTOM_EVENT_1, &MyApp::OnProcessCustom, this);

and later I throw an event of that type:

MyCustomEvent* eventCustom = new MyCustomEvent(MY_CUSTOM_EVENT_1);
eventCustom->SetEventObject(this);
this->QueueEvent(eventCustom); //this is MyApp

Unfortunately, after the event is thrown, it's never caught by OnProcessCustom.

Any ideas?

Note: Similar, but not the same as this question.

A: 

Your code looks correct so the problem is probably in the part you're not showing. Just notice that don't need to pass this as last argument to Bind() if you're calling it from a MyApp method.

I'd also advise looking at the event sample, it has working code defining a custom event (albeit using wxCommandEvent instead of a custom class but you can easily modify it to use your class instead).

VZ
Indeed the error must be in the surrounding code. Somehow I was able to get a more complicated example with a templated event class working but this is still buggy. Unfortunately no time to really figure out the problem.
John Berryman