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

查看:134
本文介绍了wxWidgets 2.9自定义事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎遵循了这个例子(在定义你自己的事件类下)),我的代码编译并运行没有错误,但我没有抓住任何地方的事件。



代码:

  class MyCustomEvent:public wxEvent 
{
// ...这里的东西
};
wxDEFINE_EVENT(MY_CUSTOM_EVENT_1,MyCustomEvent);

以后我绑定事件:

 绑定(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天全站免登陆