Starting with the Qt Framework

Although I’m far from using Linux as my main OS, I have started using it side-by-side with OS X on my desktop.  It holds a lot of promise, particularly seeing a sort of renaissance associated with the rise of Ubuntu.

On the other hand, the flexibility Linux gives to users and developers can be intimidating to deal with coming from more rigid worlds like those of Mac OS and Windows.  Regardless of what you feel about .NET and Cocoa, they’re at least consistent. Even with the improved standardization of Linux distributions and the stability of their library APIs, it’s a far cry from the safety of the world of the two more popular systems.

For several years now, Qt Software (formerly Trolltech, now owned wholly by Nokia) has offered a consistent and full-featured C++ toolkit not only for Linux but across Mac OS X and Windows as well.  It is offered in both commercial and, more recently, LGPL distributions.

Obviously a consistent, OS-native, non-bytecode-based toolkit is very desirable for performance reasons, but Qt makes another excellent addition to C++ that makes development a joy:  slots and signals.

It’s an implementation of the Observer design pattern that’s excellent for asynchronous operations that are common in GUI applications.  Importantly, it allows run-time registration of receivers and multiple-target signals, which we say are emitted from an object and received by the registered slot of other objects.

For example, suppose we have set up a button in our Qt GUI named “myButton” which emits, aptly, “clicked()” as a signal when it is clicked.  We would like to call the void function “calculate()” of the object “myCalculator” when myButton is clicked.  We can register this relationship with this single line of code:

connect(myButton, SIGNAL(clicked()), myCalculator, SLOT(calculate()));

Obviously, this isn’t the most powerful example of this mechanism since it’s merely a one-to-one relationship, but realize a signal may emit to several slots, and slots may receive signals from multiple objects, and you start to see how code can be simplified and made more intuitive.

More to come.