WxWidgets自定义事件 [英] WxWidgets custom events
本文介绍了WxWidgets自定义事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的 WxWidgets C ++应用程序中使用自定义事件,例如此处。
在我的wxApp的构造函数中:
Connect(wxID_ANY,wxCommandEventHandler(APP :: OnMyEvent));
那么应该捕获事件的函数:
void APP :: OnMyEvent(wxCommandEvent& event)
{
exit(0); // testing
}
最后,要测试它:
wxCommandEvent MyEvent(wxEVT_COMMAND_BUTTON_CLICKED);
wxPostEvent(this,MyEvent);
我启动的东西...但似乎事件没有发布或没有捕获。 / p>
有人理解此行为吗?
解决方案
以下 Connect 的重载:
void Connect(wxEventType eventType,wxObjectEventFunction函数,
/ pre>
wxObject * userData = NULL,wxEvtHandler * eventSink = NULL)
如果是这样,那么如果类型
wxID_ANY
的事件发生
您可能需要:
连接(wxEVT_COMMAND_BUTTON_CLICKED ,wxCommandEventHandler(APP :: OnMyEvent));
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 ?
解决方案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));
这篇关于WxWidgets自定义事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文