wxWidgets 2.9 自定义事件
我似乎遵循了这个示例(在“定义您自己的事件类”下找到) ,我的代码编译并运行时没有错误,但我没有在任何地方捕获该事件。
代码:
class MyCustomEvent : public wxEvent
{
//... stuff here
};
wxDEFINE_EVENT(MY_CUSTOM_EVENT_1,MyCustomEvent);
然后我绑定事件:
Bind(MY_CUSTOM_EVENT_1, &MyApp::OnProcessCustom, this);
然后我抛出该类型的事件:
MyCustomEvent* eventCustom = new MyCustomEvent(MY_CUSTOM_EVENT_1);
eventCustom->SetEventObject(this);
this->QueueEvent(eventCustom); //this is MyApp
不幸的是,在事件被抛出之后,它永远不会被 OnProcessCustom 捕获。
有什么想法吗?
注意:与此问题类似,但不同。
I appear to have followed this example (found under "Defining Your Own Event Class"), and my code compiles and runs without error, but I'm not catching the event anywhere.
The code:
class MyCustomEvent : public wxEvent
{
//... stuff here
};
wxDEFINE_EVENT(MY_CUSTOM_EVENT_1,MyCustomEvent);
and later I bind the event:
Bind(MY_CUSTOM_EVENT_1, &MyApp::OnProcessCustom, this);
and later I throw an event of that type:
MyCustomEvent* eventCustom = new MyCustomEvent(MY_CUSTOM_EVENT_1);
eventCustom->SetEventObject(this);
this->QueueEvent(eventCustom); //this is MyApp
Unfortunately, after the event is thrown, it's never caught by OnProcessCustom.
Any ideas?
Note: Similar, but not the same as this question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码看起来正确,因此问题可能出在您未显示的部分。请注意,如果您从 MyApp 方法调用它,则不需要将
this
作为最后一个参数传递给Bind()
。我还建议查看事件示例,它具有定义自定义事件的工作代码(尽管使用
wxCommandEvent
而不是自定义类,但您可以轻松修改它以使用您的类)。Your code looks correct so the problem is probably in the part you're not showing. Just notice that don't need to pass
this
as last argument toBind()
if you're calling it from a MyApp method.I'd also advise looking at the event sample, it has working code defining a custom event (albeit using
wxCommandEvent
instead of a custom class but you can easily modify it to use your class instead).