Friday, March 12, 2010
Thumbs up to QT
I am going to give a big thumbs up to QT. For those not familiar with it, QT is a development framework for C++ that can compile binaries for multiple platforms, including Windows, Linux, and the Nokia smartphone platforms. As a Gnome lover, I never gave QT much attention. I fiddled with Python on Linux, but I have not really been in the business of making desktop apps lately, and QT is very strongly tied to the KDE desktop and not to Gnome. (I actually like KDE as well, it being the first Linux desktop I ever used, but lately I have been using gnome).
Well lately things are changing. Trolltech, which made QT has been bought up by Nokia, and Nokia has made it abundantly clear that QT is the direction for developing apps on the Maemo (soon to be Meego) operating system as found on my N900 phone. On its release, Maemo was tied to a specific set of libraries around the GTK framework, but the release of QT 4.6 shows that they are serious with the switch to QT. And since QT is already strongly aligned with their Symbian operating system, it seems like a good idea.
Well imagine my surprise when, after coding with nothing by Java, C#, Python, and PHP for the last many years, I was able to slide back into using C++ and create working QT apps with almost no effort. They almost write themselves. QT uses the same simple constructive style of creating interfaces that you see in the (sadly much underutilized) Java Swing framework: simply declare your form elements and place them in a layout and they show up like you want them. But QT adds an interesting twist: slots and signals.
Slots and signals are basically the glorious bastard child of the observer pattern and an IOC framework. You create your objects (descended from either the QObject class for generic items and the QWidget class for GUI-releated items) and instead of (or in addition to) defining getters and setters you create signals and slots. Any method in your class can emit a signal at any time. Signals can be connected to slots with compatible signatures (e.g. a signal emits an integer and a slot accepts an integer). Then you can externally wire your objects/widgets together as you do in an IOC container and away you go. You do not pass dependencies around like in IOC, but you do create your objects and wire them together. If you like to think in encapsulated classes, this is an excellent framework.
In any case, I was able to get the basics working in an evening or two, and I created a GUI program that worked on my linux laptop (and, presumably, would work on Windows) that I could then recompile and deploy to my Nokia N900 phone with more effort toward the file transfer than toward making it work. What looked like a native app on my laptop looked (differently) like a native app on my phone. And it worked.
And, I should add, the framework is extremely thorough and fun to use. Alot of the good stuff you find in Java and C# is packed into the QT classes, making things like threads, Strings, timers, etc., easier to use. There don't seem to be any standard phone-related libraries (e.g. accessing the accelerometer, intercepting SMS messages, etc.) but every time I dig around I find that those things are fairly easy to deal with on the N900 due to its Linux heritage.
The downside seems to be licensing. I have no idea what I would have to buy in order to sell an app created with QT. But given that I am only looking at goofing around with free, open source software right now, QT is free to use and I give it a big thumbs up.