Klaus
Klaus

Reputation: 1251

WxWidgets custom events

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 ?

Upvotes: 3

Views: 2605

Answers (1)

UncleBens
UncleBens

Reputation: 41351

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));

Upvotes: 2

Related Questions