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

Qt Attracting Interest Among Application Developers

by Cameron Laird

Related Articles

Boudewijn and Cameron Argue for Qt

Visual Design With Qt

"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:

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:

#include <qapplication.h>
#include <qpushbutton.h>

int main(int argc, char **argv)
    QApplication example(argc, argv);

    QPushButton quit("Quit", 0);
    quit.resize(75, 30);

    QObject::connect(&quit, SIGNAL(clicked()), &example, SLOT(quit()));

    return example.exec();

Trolltech documentation thoroughly explains component-based development.

More Qt highlights

Qt is also a leader in "internationalization," that is, the ability to create displays appropriate to different countries and human cultures. Qt fully supports, for example, Unicode, which gives it the ability to show not just the alphabet used for English and all the other Western European languages, but also Russian, Arabic, Hebrew, other oriental languages, and essentially all written human tongues.

I've heard that many programmers also like Qt for its outstanding documentation. Trolltech has been quite successful at providing tutorials and references that make developers feel "at home" with the toolkit.

Trolltech has also been aggressive in striking business deals that support development goals. Qt OpenGL is an extension to Qt which makes the OpenGL library fully available to Qt programmers. Trolltech has been innovative in setting up licenses which simultaneously protect both its revenue and developers' need for transparency and accountability.

All these strengths, along with more technical ones beyond the scope of this introduction, simplify development and maintenance of sophisticated GUI applications with Qt. Qt is particularly capable on the "high end" of high-speed or high-complexity GUI programs. The result is that some of the most important GUI projects that have appeared in the last few years have been based on Qt:

The most famous of all the Qt-based projects is the KDE desktop environment which ships with several Linux distributions. KDE is a showcase for Qt flexibility and performance.

The end-user experience

Is there a payoff in all this cool developer-functionality for end-users? How do users react to the visual displays made by Qt-based applications?

Most developers understand that the shape of widget corners and calculation of border widths is essentially a fashion industry. However, Qt has a couple of characteristics that make it look like a winner in this arena.

The first design strength is that it has reasonable, and even exciting, defaults. Suppose a system administrator writes a minimal Qt-based control panel to mediate his customers' use and configuration of a command-line program. The smallest Qt application has a distinctive appearance and behavior that's widely seen as "professional" and occasionally "pretty." Even in these very simple cases, Qt brings end-users a level of comfort.

At the same time, one of Qt's customizability dimensions is support for "themes." What this means to end-users is that a Qt application can look entirely like a Windows application, for example, whether it's hosted on a Windows or Unix machine. It could also look like a Motif application. In fact, the same application can have either appearance, or one of several other selections, independently of the underlying OS. What's more, the selection between the appearances is open not just to the programmer, but to the end-user as well. Users can configure a properly written "themed" application to fit their personal preferences or organizational standards.

Trading skins

These possibilities hint at the excitement currently stirring the world of GUI toolkits. In the past, many programmers and independent software vendors (ISVs) specialized as "Windows programmers" or "Unix shops." Now, a sufficiently compelling application has the potential to be far more universal. Qt-based applications are in step with this trend because they run correctly on Windows and Unix, and they look good on each. In principle, Qt and other toolkits with comparable strengths have the potential to grow beyond the confines of any single OS or CPU.

Who's using Qt?

So is everyone using Qt? No, at least not yet. Many development organizations have a substantial investment in older toolkits, including third-party packages that enhance their value. Tk and Visual Basic are easier for beginners, at least in several common situations. More crucially, organizations with an interest in MacOS generally use Tk or one of the specialty toolkits, because Qt is not yet available for MacOS. "Development [of Qt for MacOS] has started, but it's too early to estimate a release date," according to Trolltech Product Manager Eirik Aavitsland. Trolltech programmers are currently targeting "both MacOS 8/9 and MacOS X support," according to Aavitsland.

Qt's approach to licensing

Most objections to Qt appear to involve its license. GUI toolkits span a wide range in the liberality of their licenses. Qt occupies a position somewhere in the middle. Aavitsland summarizes, "For commercial developers, Qt has a normal commercial library license, and there aren't even any run-time fees or royalties."

Trolltech's Free Edition is less conventional. The company deliberately chose a nearly unique business model in simultaneously "offering the full freedom of the open-source world while at the same time ensuring active development and support by a professional company. This makes Qt an attractive choice for both commercial and open source development," in Aavitsland's words. Unlike other companies -- JavaSoft, Digital Creations, Metro Link, Caldera, and many others -- searching for a similar balance, Trolltech has explicitly created distinct but linked licenses targeted for both worlds.

Trolltech provides a Free Edition for Unix-based development and deployment of open-sourced and noncommercial applications. Noncommercial applications can also be delivered to Windows end-users without licensing fees. However, the only development package available for Windows has a purchase price -- over $1500 US, as of June 2000 -- high enough to discourage casual hobbyists.

Price isn't the only complaint raised about the license. For a variety of ideological and strategic reasons, certain organizations turn away from Qt, often to the GNU Programmers Licensed (GPLed) Gnome toolkit (GTK). Trolltech is well aware of the controversy.

Among its responses to Qt's user community was the March 1999 introduction of "QPL," the Qt Programming License, which refined the terms of the Free Edition. QPL differs from GPL principally in its treatment of in-house commercial work -- the applications a business writes to manage its own operation, for example. QPL encourages such businesses to pay Trolltech for a commercial license. Aavitsland concludes, "We are working on straightening out the few remaining Free Edition license issues."

Cameron Laird is the vice president of Phaseit, Inc. and frequently writes for the O'Reilly Network and other publications.

Related Articles

Boudewijn and Cameron Argue for Qt

Visual Design With Qt

Discuss this article in the O'Reilly Network Forum.

Return to the O'Reilly Network Hub.

Copyright © 2009 O'Reilly Media, Inc.