wxWidgets - 事件表vs Connect()? [英] wxWidgets - Event table vs Connect()?

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

问题描述

我刚刚开始学习wxWidgets 3.0版本,用C ++。我注意到,wxWidgets中的事件处理是由事件表完成的。但是一个教程还提到了Connect() - 实际上它只是说:本教程将使用事件表,而不是Connect()。

I have just started learning wxWidgets, version 3.0, with C++. I have noted, that event handling in wxWidgets is done by Event tables. But one tutorial also mentioned Connect() - actually it just said : " this tutorial will be using event tables, not Connect() " .

事件表和Connect()后面的哲学是什么?有什么区别,什么时候比另一个更合适...谢谢。

I would like to know, what is the philosophy behind Event tables and behind Connect() ? What is the difference, when is one more suitable than the other... Thank you.

推荐答案

Connect()已被 Bind()

First, don't use Connect() which was superseded by Bind() which is better in every way.

其次,静态(使用事件表)和动态(使用 Bind())处理事件的方法工作,你可以使用任何你喜欢的。就个人而言,我建议使用 Bind(),因为

Second, both static (using event tables) and dynamic (using Bind()) methods of handling events work and you can use whichever you prefer. Personally, I recommend using Bind() because


  1. 可以用于将一个对象上的事件连接到任何其他对象,甚至是一个自由函数,或者在C ++ 11中,
  2. 它更安全,可以捕获最常见的错误,例如在编译时使用错误的事件处理程序签名。

  3. 这是动态,即您可以随时连接和断开处理程序。

事件表是


  1. 它们稍短一些,特别是在3.0之前的版本。

  2. 在文档,示例,教程中更常见,只是因为他们在 Bind()上有15年的开始。

  1. They are slightly shorter, especially in pre 3.0 versions.
  2. They are much more common in documentation, examples, tutorials, ... just because they had a 15 year head start on Bind().

然而,它们是笨拙的使用,因为他们需要子类化(派生一个新类)一个对象,以处理非命令事件,它们并不检测所有编译时的错误,允许你编写很好的代码,但在运行时崩溃。

However they are clumsier to use because they require subclassing (deriving a new class from) an object in order to handle non-command events in it and they don't detect all errors at compile-time allowing you to write code that compiles fine but crashes at run-time.

这篇关于wxWidgets - 事件表vs Connect()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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