Appendix D. Comparison with other signalling systems
Prev |  | Next

## Appendix D. Comparison with other signalling systems

TODO: Rewrite this paragraph and talk about QT's moc. (An aside: GTK+ calls this scheme "signalling"; the sharp-eyed reader with GUI toolkit experience will note that this same design is oft seen under the name of "broadcaster-listener" (e.g., in Metrowerks' PowerPlant framework for the Macintosh). It works in much the same way: one sets up `broadcasters`, and then connects `listeners` to them; the broadcaster keeps a list of the objects listening to it, and when someone gives the broadcaster a message, it calls all of its objects in its list with the message. In gtkmm, signal objects play the role of broadcasters, and slots play the role of listeners - sort of. More on this later.)

gtkmm signal handlers are strongly-typed, whereas GTK+ C code allows you to connect a callback with the wrong number and type of arguments, leading to a segfault at runtime. And, unlike QT, gtkmm achieves this without modifying the C++ language.

Re. Overriding signal handlers: You can do this in the straight-C world of GTK+ too; that's what GTK's object system is for. But in GTK+, you have to go through some complicated procedures to get object-oriented features like inheritance and overloading. In C++, it's simple, since those features are supported in the language itself; you can let the compiler do the dirty work.

This is one of the places where the beauty of C++ really comes out. One wouldn't think of subclassing a GTK+ widget simply to override its action method; it's just too much trouble. In GTK+, you almost always use signals to get things done, unless you're writing a new widget. But because overriding methods is so easy in C++, it's entirely practical - and sensible - to subclass a button for that purpose.

Prev | Up | Next
Appendix C. Creating your own signals | Home | Appendix E. gtkmm and Win32