2009-08-13

Qt - signals and slots

Max is used to be a hardcore supporter of fox-toolkit for C++ GUI developement. Fox is a good, free and cross-system library. But Max always has some kinds feeling that Fox-toolkit may miss something important. Until today Max read something about Qt, another open source GUI library, he came to realize that fox-toolkit may somehow be short of good communications between different components. Interaction between Fox GUI components is possible but not straight forward. In contrast to Fox-toolkit, Qt uses a smart way - signals and slots - to let different component to talk to each other.

See the introduction of "Signals and Slots".



From the design pattern point of view, "Signals and Slots" in a certain sense follows the idea of "Command Pattern". The basic idea is to let two objects to work together, but they don't need to know each other. It sounds a little wired, but it can significantly simplify the design, coding and maintaining. With help of this mechanism, components can be better encapsulated and full decoupled to each other. The connection between objects is built up by a simple QObject::connect() function calls. You can connect as many signals as you want to a single slot, and a signal can be connected to as many slots as you need.

The other common methods for the interaction between GUI objects:
  • Callback function
  • Event
  • Data binder.


Reference:

1 comment:

  1. I like fox as its lightweight and less complex than qt. FOX has workarounds in any situation like C++. Qt does present some stonewalls now and then.

    My 2 cents

    ReplyDelete