wxWidgets 2.9自定义事件 [英] wxWidgets 2.9 custom events

查看:210
本文介绍了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); //这是MyApp

不幸的是,事件被抛出后,OnProcessCustom p>

任何想法?



注意:类似,但不同于这个问题

解决方案

您的代码看起来正确,所以问题可能在您的部分不显示。只要注意,不需要传递作为的最后一个参数Bind()如果你调用它一个MyApp方法。



我还建议查看事件样本,它有工作代码定义一个自定义事件(虽然使用 wxCommandEvent 而不是自定义类,但您可以轻松地修改它使用您的类)。


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.

解决方案

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 to Bind() 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).

这篇关于wxWidgets 2.9自定义事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆