views:

119

answers:

1

Hello,

I'm trying to use a custom event in my WxWidgets C++ application, like described here.

In the constructor of my wxApp:

Connect(wxID_ANY, wxCommandEventHandler(APP::OnMyEvent));

Then the function that should catch the event:

void APP::OnMyEvent(wxCommandEvent& event)
{
    exit(0); //testing
}

Finally, to test it:

wxCommandEvent MyEvent(wxEVT_COMMAND_BUTTON_CLICKED); 
wxPostEvent(this, MyEvent);

I launch the thing...but it seems that the event is not posted or not caught.

Does someone understand this behaviour ?

+2  A: 

You appear to be using the following overload of Connect:

void Connect(wxEventType eventType, wxObjectEventFunction function, 
    wxObject* userData = NULL, wxEvtHandler* eventSink = NULL)

If so, then should an event of type wxID_ANY happen (never?), then the connected function will be called.

Perhaps you need:

Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(APP::OnMyEvent));
UncleBens
Excellent, it works perfectly, thank you :) I thought wxID_ANY would be any kind of event... It is not the case ?
Klaus
Added a link to the documentation. You won't get away without telling which type of event you want to handle. The `id` should be an identifier of the widget from which the event came from. (E.g let this function handle events of type `wxEVT_...` which came from a widget with a particular (or any) identifier.
UncleBens
Ok, thank you for the precision :)
Klaus
@UncleBens - If you have anything to say about my question (http://stackoverflow.com/questions/4037525/wxwidgets-2-9-custom-events) I would appreciate it.
John Berryman