"It does everything I need." That's what many application developers, especially in Europe, say about Qt. This week, the O'Reilly Network profiles the graphical user interface (GUI) toolkit Qt, and explains who's using it and why.

Widget sets for GUI construction

Buttons, menus, text displays, graphic images, along with a mouse or similar pointer -- these are the on-screen fundamentals most contemporary computer users recognize.
For end-users, what's important is that buttons click consistently and fonts display crisply. Very few programmers directly code these visual elements. Instead, they rely on GUI toolkits, or, as they were often called until just a short time ago, "widget sets." These are "parts boxes" of standardized buttons, labels, and other displays that developers combine to synthesize a working interface. "Widget" is the industry jargon for these standard graphical pieces.

From the outside, a toolkit has two aspects. First, its application programming interface (API) specifies how coders use it. The second aspect is the bundle of visual
appearances the toolkit provides. Qt has advantages in both these areas.

Qt portability

The most prominent toolkits for most of the last decade were Microsoft Foundation Classes (MFC) for Windows, and Motif for Unix and the MacOS. These toolkits had very
little portability outside their natural homes. For example, people have tried to implement Motif for Windows, but the results have generally proven to be expensive, fragile, and incomplete.

In contrast to these, Norwegian-based Trolltech AS deliberately designed Qt to be portable and currently makes versions available "for Microsoft Windows and all major brands of Unix," according to its web site. Moreover, in mid-June, Trolltech released Qt/Embedded, a version of Qt for embedded applications running Linux which does not require the X11 windowing software typical of Unix workstations. This means that, for the first time, programmers can use the same practical GUI toolkit for both their desktop and dedicated-embedded hardware. By doing so, we may see faster development of full-featured television consoles, kitchen appliances, automotive control centers, portable communicators, and the explosion of other embedded devices.

Qt's growth was rapid even before introduction of Qt/Embedded, though. Programmers like its clean design. GUI work has long been seen as a particularly apt area for object-orientation, that is, expression of programming solutions in terms of "object" constructs. Widgets are natural examples of objects, in the computing sense. However, historical contingencies have left the dominant widget sets incompletely object-oriented, and correspondingly clumsy to code efficiently.

One example of Trolltech's intelligently portable design is its QPainter rendering class. It's simultaneously efficient in operation and general in application.
"General" means here that a programmer has full control of whether QPainter paints to a:

Traditional displayable widget,

Off-screen pixmap (for animation and other high-speed work),

On-disk picture (metafile), or ...

... a PostScript printer.

This is typical of the flexibility and uniformity of the Qt API.

Components and other virtues

This care in design is also important because GUI programming differs from traditional application work in that its fundamental requirement is to handle "events." Older computing models were more sequential: The computer first does one thing, then
another, and continues to completion.

With a GUI, however, the job of the computer is roughly to set up a display, wait for a user action (a click somewhere on the screen, or a keystroke, for example), respond to that action, then wait for the user again. "Callback" is the technical label for the functionality that creates these dialogues. When a user clicks on a selection, the computer "calls back" to a piece of code that's already been defined. However, such popular languages as C and C++ were originally designed for more sequential processing.
Callbacks have always had a slightly uneasy position in C and C++; their integration with the rest of these languages is a bit bumpy.

Qt, in contrast, has a strong object-oriented design, implemented in the C++ object-oriented language. Moreover, the Qt designers invented a novel mechanism
of "signals and slots" to express callback requirements. Signals and slots make it easy to use good C++ style in coding GUIs. In particular, Qt has been more successful
than other toolkits at encouraging production of customized "components," that is, specialized widgets that can be engineered once and used many times. Even the
simplest "Hello, World" hints at this capability: