Special Events WxWidgets

I am trying to use a custom event in my WxWidgets C ++ application, as 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 check this out:

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

I am launching a thing ... but it seems that the event is not published or not found.

Does anyone understand this behavior?

+3
source share
1 answer

It seems you are using the following Connect overload :

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

If so, should there be an event of type wxID_ANY(never?), Then the called function will be called.

Perhaps you need:

Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(APP::OnMyEvent));
+2

Source: https://habr.com/ru/post/1742688/


All Articles