O'Reilly Network    
 Published on O'Reilly Network (http://www.oreillynet.com/)
 See this if you're having trouble printing code examples

What's New in Qt 2.2.2

by Boudewijn Rempt

The Qt Palmtop Environment

Palmtop is becoming an exciting area of Linux development. While most Linux PDA projects are still vaporware (see All Linux PDA: Fact or Fiction), other projects have come to full fruition. One of these is the Qt Palmtop Environment.

Qt Palmtop is licensed under the GPL. You can download the source these ways: a binary that runs on top of Linux, a binary that runs from a single boot floppy on any PC, a binary for the iPAQ, or a binary for the Cassiopeia.

The package is fairly large -- about 2.5 MB. Another project, Microwindows, has delivered a a package that needs a mere 100 KB for its environment, but that excludes the base OS and all applications.

Qt Palmtop is more than just a GUI and a window manager. It offers a choice of input methods (handwriting, picklists, Unicode) and all the utilities you need on a palmtop plus games and even an MPEG player!

Now you can comfortably run a Linux-based PDA and have it do everything that you want it to do. Hack it as much as you like! Qt Palmtop offers all the features of Qt for Windows or X11, such as the canvas, plus new features such as handwriting recognition.

Go to Troll Tech, and start playing...

I just spent some time with the final release of Qt 2.2.2. Qt is best known as the toolkit underlying KDE, but it's also a very complete cross-platform C++ toolkit in itself, used by an increasing number of commercial applications such as Opera.

Qt applications can be run on three platforms: Unix/X11, Windows, and embedded Linux. Qt has been certified open source since version 2.0, the Unix/X11 version is released under GPL since version 2.2, and the embedded version is GPL since version 2.2.2. The Windows version remains proprietary in the sense that developers need to pay for a license, but there are no run-time restrictions. For instance, the GPLed Python bindings to Qt, PyQt, are available freely with a Qt dll for Windows.

Qt Designer is beautiful GUI

What's new in Qt 2.2? The coolest, most impressive addition is Qt Designer. This is a great GUI design utility. I've reviewed Qt Designer before (see Visual Design with Qt), but to sum it up: Qt Designer is a very stable, very easy-to-use dialog designer. It is especially good in creating complex dynamic layouts (helped by Qt 2.2's vastly improved layout managers) and in supporting the well-known signals/slots architecture.

The design is sensible: There's a separate GUI designer that saves the designs in an XML formatted file, and a compiler, uic, that takes the design files and creates C++ code. This opens up the possibility of writing all kinds of extensions to the system, and indeed, there is already a pyuic available that can generate Python code instead of C++. Designer is a truly wonderful tool, and now with version 2.2.2, it can even import the Microsoft standard .RC dialog resources files.

OpenGL, XML modules, and more

With Qt 2.2, the toolkit has certainly become very comprehensive, offering almost everything that's needed for application development, and Troll Tech has decided to split the library into several modules. Paying customers can choose between a professional and an enterprise edition, the difference being the number of modules they receive. Users of the free edition get the full set, but their development has to be open source, too.

You can choose which modules are compiled into the library, but you cannot compile modules into smaller, separate libraries.

The following modules are available:

XML parser and DOM implementation

The advent of Qt Designer has brought about several other new features. Most notable amongst these is the XML parser and DOM tree implementation. The parser has a SAX2-compliant interface, but the naming is adapted to the Qt standards. This fast XML parser has already been very useful in the development of the upcoming KDE 2 desktop.

Another improvement that should come as a godsend to developers is the QAction/QActionGroup combo. This is a mechanism whereby a certain user interface action can be defined at once both for a toolbar and a menu item, together with accelerator keys. These actions can then be logically grouped in QActionGroups. I've been building something like this time and again for my own applications ever since Qt 1.44, but never getting it really right, and the Troll Tech implementation works very well indeed.

Troll Tech has taken some flack for their QString class, with detractors arguing that Troll Tech should use the standard C library string. However, QString offers excellent Unicode support, and Troll Tech is committed to bringing the same level of Unicode support to Unix/X11 as Windows 2000 has. The standard C library string just doesn't offer that.

And Qt offers a decent mechanism for producing localised applications, too. Version 2.2.2 brings numerous improvements to this area, with expanded support for Chinese and Thai. Internationalisation is further helped with the BSD-style licensed Qt Linguist.

Qt has now started building real support for threading, with QMutex, QSemaphore, QCondition, and QThread. Other extremely usable classes are available for networking applications, like QSocket, QServerSocket, or QNetworkOperation, and for encoding text, like QTextCodec, QTextEncoder, and QTextDecoder.

Properties -- useful or just added weight?

One relatively new feature that's heavily used by Qt Designer is the property concept. No longer is it necessary to use functions to get and set certain properties of widgets, such as font. Instead, we have a property mechanism that is implemented as a moc (Meta Object Compiler) macro, Q_PROPERTY. Together with this feature comes a new class, QVariant, which is a union for the most common Qt data types -- this enables a single mechanism to handle the property settings.

I've been told that the original intention with Q_PROPERTY was to make it easier to create bindings of Qt to scripting languages -- however, neither PyQt nor PerlQt, the currently best developed bindings, really need the feature. Indeed, it is quite possible to use functions everywhere, instead of properties.

As it is, the property mechanism is completely superfluous, creating a second way of doing the same thing, and I find the QVariant class to be a monstrosity that keeps reminding me of Visual Basic's Variant data type. I think Qt would have been cleaner and more usable without it.

New table widget is hot; others so-so

A great addition, and one that hasn't received nearly enough press, is the new table widget. This is finally an editable spreadsheet-like control. Users of Qt have been clamoring for this for years, as it is absolutely essential for all kinds of business and database applications. No longer have people to work with the difficult old QTableView, which was prone to all kinds of nasty bugs.

In the category "nice, but I don't need it" falls the QDial widget, a rounded range control like a speedometer.

The QMultiLineEdit widget is still relatively underpowered -- it doesn't support rich text and is completely line oriented, being built on QTableView. For Qt 3.0, a new and fancy QTextEdit widget is being promised, which will support rich text just like the display-only QTextView widget that is included in Qt 2.2. KDE developers have an advantage here, as they can embed the powerful KWrite text-editor widget or the KWord word processing widget in their applications through the KParts mechanism.

Interface improvements

The widget appearance has improved -- the Motif style is no longer exactly Motif, but a bit more elegant. An SGI-like style has been added, and a GTK-like style. Both reproduce the look and feel of these toolkits very well. My favourite style is still Platinum, which evokes the updated Mac look introduced with Mac OS 8. And it's as easy as ever to create new, fast widget-themes yourself.

There is now support for cute fade and scroll effects for popup and MDI windows. MDI is relatively new too -- Qt 2.1 introduced the QWorkspace class that makes it possible to write windows-style MDI applications. The trend in user-interface design is going to SDI everywhere, with one window for each document, but MDI is certainly very useful for a large class of applications, such as IDEs.

License issues

Troll Tech has drawn much criticism for their licensing approach in recent years. When they first made their library available for free software development years ago, I interpreted it as a gesture meant to support free software, not as a nasty corporate plot to get as many free demos as possible. But this was long ago -- in a time when people were actually using binary-only toolkits like XForms.

The success of the KDE desktop has changed that, and Troll Tech has finally decided to make Qt for Unix/X11 available under the GPL license. This is important, because it should help dampen a lot of unfair criticism, but in practice, little changes. The only new "right" is to distribute modified versions of Qt instead of distributing patches. Since we're talking GPL instead of LGPL, developers of closed source software still have to buy a developers license from Troll Tech, and until someone takes the GPL version of Qt and ports it independently to Windows, nothing changes for Windows developers, either.


Troll Tech



Related Articles:

Qt Designer

Qt Attracting Interest Among Application Developers

Boudewijn and Cameron Argue for Qt

The addition of a GPL license for Qt Embedded can become quite important, though. Even though X11 is still serviceable, it is showing its age, and some widely desired effects. such as anti-aliased font handling, are difficult to implement. Qt Embedded, which runs just as well without X11, can change that. Imagine a KDE 2 desktop that runs on Qt Embedded -- it would look very professional, won't carry any excess baggage, and would be an attractive proposition for vendors of distributions geared towards beginners.

Final thoughts

Qt has always been a cleanly engineered, full-featured toolkit. In the past, people have complained about its look-and-feel (although at the time when Qt offered a choice between Windows and Motif look-and-feel, no other toolkit existed that gave as much choice), but with 2.2.2, that should be over. Another serious objection to Qt -- the lack of a professional, extendable GUI designer -- has been answered too. By offering support for Unicode, localisation, and internationalisation both on Unix and Windows, Qt provides a strong basis for modern application development. Besides the rich set of widgets, Qt now offers many utility classes with well-thought-out interfaces that are easy and safe to use.

In sum, Troll Tech have created a complete environment where developing cross-platform applications in C++ has become as easy, if not easier, as developing in Java.

Boudewijn Rempt is a senior developer with Tryllian, a mobile agent company. He has worked with PyQt since its inception.

Discuss this article in the O'Reilly Network Forum.

Return to the O'Reilly Network Hub.

Copyright © 2009 O'Reilly Media, Inc.