WxWidgets custom events

拜拜、爱过 提交于 2019-12-23 18:33:46

问题


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 ?


回答1:


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


来源:https://stackoverflow.com/questions/2709124/wxwidgets-custom-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!