First, do not use Connect() , which has been replaced by Bind () , which is the best.
Secondly, both static (using event tables) and dynamic (using Bind() ) event handling methods work, and you can use whatever you prefer. Personally, I recommend using Bind() because
- It is much more flexible: it can be used to connect events on one object to any other object or even to a free function or, in C ++ 11, lambda .
- This is safer and catches the most common errors, such as using the wrong signature of the event handler at compile time.
- It is "dynamic", i.e. You can connect and disconnect the handler at any time.
The main advantages of event tables are:
- They are slightly shorter, especially in versions prior to 3.0.
- They are much more common in documentation, examples, textbooks, ... just because they had a 15-year start on
Bind() .
However, they are inconvenient to use because they require a subclass (getting a new class) of the object to handle non-command events in it, and they do not detect all errors during compilation, which allows you to write code that compiles normally, but fails during fulfillment.
source share