PDA

View Full Version : should event filters be used only for debugging



babu198649
21st November 2007, 14:12
hi
is it right to use event filters in the final program. does it slows the execution speed.

jpn
21st November 2007, 14:59
I think it's mostly a matter of taste. Overriding an event handler in most cases results to cleaner solution than installing an event filter. Latter might save you from subclassing but the functionality ends up into a "wrong" class.. that is, from the object-oriented point of view. My advise would be to try to avoid event filters as much as possible. Naturally, event filters have their own use cases like handling a group of children or working around limitations in Qt. :) But in my opinion, you really shouldn't use them as number one approach to implement new functionality.

Then, about efficiency. Of course, event filters are an "extra step". Every single event received by the target object goes first through all installed filters (unless one of them returns true, which means the event is eaten and event processing stops) and finally reaches its actual target. But it shouldn't have any dramatical slowdown effect unless you do something stupid (read: time consuming) in the event filter function. Notice that one can even install event filters on the whole application object itself.