Qt/Embedded: The C++ Embedded GUI Application Developer's Toolkit
Qt/Embedded: The C++ Embedded GUI Application Developer's Toolkit
Technical Overview
Abstract
© 2001 Trolltech AS
Qt is a trademark of Trolltech AS.
All other company and product names are trademarks or registered trademarks of their respective owners.
Contents
Contents................................
Contents................................................................
................................................................................................
..........................................................................................
.......................................................... 2
Introduction................................
Introduction ................................................................
................................................................................................
....................................................................................
.................................................... 3
System Requirements................................
Requirements................................................................
.......................................................................................................
................................................................
....................................... 4
Memory requirements............................................................................................................................ 4
Screen requirements............................................................................................................................... 4
Processor requirements........................................................................................................................... 5
Architecture ................................................................
................................................................................................
....................................................................................
.................................................... 6
Cross-platform development .................................................................................................................. 6
Look and feel ........................................................................................................................................ 6
Component programming...................................................................................................................... 7
Qt/Embedded Windowing System ......................................................................................................... 8
Internationalization ............................................................................................................................... 9
Layout management ............................................................................................................................ 11
Customizing widgets............................................................................................................................ 12
Qt Virtual Framebuffer........................................................................................................................ 13
Qt Virtual Network Computer Server................................................................................................... 13
Qt Palmtop Environment ................................................................
..............................................................................................
.............................................................. 14
Visual Development ................................................................
................................................................................................
......................................................................
...................................... 15
Device independent graphics ................................................................................................................ 16
Special paint devices ............................................................................................................................ 16
The 2D graphics API ........................................................................................................................... 16
Image handling.................................................................................................................................... 17
Canvas ................................................................................................................................................ 18
3D graphics......................................................................................................................................... 18
Tool Classes ................................................................
................................................................................................
..................................................................................
.................................................. 20
Operating system services..................................................................................................................... 20
Text classes.......................................................................................................................................... 21
Collection Classes................................................................................................................................ 21
Network Classes .................................................................................................................................. 22
Trolltech Embedded Partnerships................................
Partnerships ................................................................
..................................................................................
.................................................. 24
Appendix 1: Complete API Class List ................................................................
............................................................................
............................................ 25
Early Embedded Operating Systems (EOS) were typically proprietary and expensive much like the
early UNIX and Windows operating systems. However, as Linux matured, making steady gains in the
server and desktop markets, embedded systems developers started to realize that open source and free
resources could also be used to create EOSs. Linux quickly became a viable alternative to existing,
closed-source embedded platforms.
Because Linux is open source, it is fairly simple for developers to make the changes required for the
relatively strict memory and processor demands of embedded systems, and many companies have been
able to produce some embedded version of Linux. As such, embedded Linux is steadily gaining
momentum and is becoming one of the most popular embedded platforms.
Over time, production technologies and hardware performance also improved. Embedded devices
such as mobile phones and Personal Digital Assistants (PDA) greatly benefited from this development.
From a hardware point of view, the stage was set for rich, first class GUI applications on embedded
devices.
During the fall of 1999, Trolltech realized that embedded Linux and improved embedded hardware
had made it viable to put first class GUI solutions on embedded devices. In August 2000, less than a
year later, Trolltech presented Qt/Embedded to the public. Being easily adaptable and configurable,
major customers, like Ericsson of Sweden, and partners, like Mizi Research and PalmPalm
Technologies of Korea, had soon employed Qt/Embedded on a multitude of hardware. On the low
end, Mizi had Qt/Embedded running on its SmartPhone with 18 MHz ARM7 processors with only 2
MB of DRAM and 4MB flash. On the higher end, Trolltech made Qt/Embedded run on Compaq’s
iPAQ with 206 MHz strongARM processors and 32MB of RAM.
This document discusses some of the important features of Qt/Embedded and how they have been
designed specifically to offer richness, speed and versatility with a reduced memory footprint. One
hundred percent source code compatible with the proven Qt/Windows and Qt/X11 frameworks,
Qt/Embedded provides a rich GUI API for creating embedded applications.
Qt is a product of Trolltech. It has been on the market since 1995, and has been used by leading
companies such as HP, IBM, Intel, Siemens, Ericsson, and Pixar. Widely used on Linux, Qt is the
basis for the popular KDE desktop environment included in every Linux distribution.
A detailed presentation of all the functionality provided by Qt is outside the scope of this document.
Further technical information can be found in:
The most current list of available documentation can be found on-line at www.trolltech.com.
Qt and Qt/Embedded are continuously evolving toolkits. This document presents the main features
of Qt/Embedded version 2.2.3. Further information about Qt and Qt/Embedded is available at the
Trolltech web site at www.trolltech.com.
Qt/Embedded has been designed to be memory efficient, to be responsive even on slow processors and
to provide crisp and vivid graphics on a multitude of displays.
Memory requirements
One of the most critical components in an embedded device is memory, which heavily influences the
production cost of the entire device. As this document is being written, 8 and 16Mb of ROM/RAM is
still fairly common, while high-end devices are starting to employ 32Mb and even 64Mb. The
Qt/Embedded design team made two major decisions that contribute to the low memory footprint of
Qt/Embedded: memory customization and X graphics independence.
By picking and choosing features, a user can reduce the memory demands of Qt/Embedded to 670
KB. At this level, while it is possible to create simple applications and the event mechanism is
functional, most widgets necessary to form a rich GUI are not available. For first class GUI
applications, a library size of 1.5 - 3Mb is more common. Due to the rich feature set of
Qt/Embedded, applications are generally much smaller than those using other toolkits or X11
directly.
No need for X
The X system relies on an elaborate mechanism for handling displays. As advantageous and popular as
this system has become on networked workstations and even some desktops, it makes little sense on
most embedded devices. By offering an efficient windowing system and doing all graphics directly in
the frame buffer, Qt/Embedded avoids the memory and time overheads of the X system.
Clearly, Qt/Embedded benefits from the same reference-counting and copy-on-write techniques
found in all other Qt implementation. This means that many classes are implemented so that copies
of the same object share the same data in memory. This saves unnecessary copying of the data, and it
reduces the memory demands of the application as a whole. This technique is especially effective when
applied to classes that contain large amounts of data, such as pixmaps and images, and for frequently
used classes, such as strings. X independence also allows for a variety of display features that have been
incorporated into Qt/Embedded. Screen Rotation, Anti-aliased fonts, and alpha-blended pixmaps are
the key display advantages.
Screen requirements
Qt/Embedded has been designed to support a multitude of screen sizes, resolutions and bit depths.
In fact, Qt/Embedded is independent of hardware and will work with any combination of processors
and graphics cards supported by Linux.
Qt/Embedded requires frame buffer support on Linux. Currently, 1, 4, 8, 15/16, 24 and 32 bits per
pixel (bpp) depths as well as VGA16 are supported, allowing Qt/Embedded to run on most embedded
Linux devices. The Qt/Embedded applications access the video frame buffer directly.
Accelerated drivers for Qt/Embedded can also be used for improved performance. Such drivers access
the graphics hardware directly to utilize any available hardware acceleration of graphics operations.
Processor requirements
All platforms supported by Linux can have Qt/Embedded ported to them easily, and may even work
“out-of-the-box” if they use one of the supported frame buffer depths. This includes CPUs based on
the ARM/strongARM, x86, Motorola 68000, MIPS, and PowerPC chips. Various groups and vendors
are developing other embedded Linux platforms. Qt is highly portable, and Trolltech offers expert
porting services to those with special requirements.
Cross-platform development
Qt is cross-platform, in the sense that the Qt class library is implemented for several different
operating and window systems. The API is identical for all platforms. This means that an application
written with Qt on one platform can be made to run on another by simply recompiling it on the new
platform, and linking it with the Qt library for that platform. In fact, the Qt library is binary
compatible on all supported Windows variants. Thus, with Qt, software producers can develop and
maintain an application for multiple platforms by developing and maintaining a single application
source code base. This means it is no longer necessary to learn yet another proprietary, embedded
GUI API just to create embedded applications. Another benefit is that Qt/Embedded gives instant
portability of existing Qt-based software to embedded Linux systems.
Qt is currently implemented for three main groups of operating systems, as shown in Figure 1:
• UNIX: this includes Linux, HP-UX, Sun Solaris, Digital UNIX, SGI Irix, IBM AIX, SCO
UNIX, and several BSD variants. The Qt library is implemented using the X11 libraries, and
uses the X Window system.
• Windows: this includes Windows 95, 98, NT and 2000. The Qt library is implemented
using the Windows GDI API, and uses the Microsoft Windows window system.
• Qt/Embedded library includes a complete window system and can be easily targeted to any
display and input hardware.
Figure 1: Qt Platforms
Single-Source Qt Application
Qt API
Implementations for other operating and window systems are being considered.
• Motif style: emulates the classic Motif look and feel. This is the default style of Qt-based
applications running under X11.
• CDE style: a variation of the Motif style which emulates the lighter Motif look and feel
that has become popular in the recent years.
• Windows style: emulates the Windows look and feel. This is the default style of Qt-based
applications running under Windows.
• SGI: more closely emulates another popular and lighter Motif look and feel.
In addition, an API is provided for implementing custom styles. This means that for applications that
have special demands regarding visual appearance, e.g., a kiosk application, it is fairly straightforward
for the programmer to implement a custom look and feel. All visual elements in Qt will then present
themselves using this custom look and feel style.
Component programming
In object-oriented software development, it is desirable to structure the application code in
independent, reusable components. This principle is known as component programming. Qt offers
assistance with this task through a special inter-object communication mechanism called signals and
slots. This mechanism allows objects to emit anonymous signals that cause slot functions in other
objects to be executed. This form of inter-object communication is similar to Motif callbacks and
MFC message maps, with some important advantages.
• All classes defining either signals or slots must come from the Qt base class QObject.
• A QObject class may define any of its (otherwise normal) member functions to be slots.
• A QObject class may define that it is able to emit certain signals. Each signal has a name
and a parameter list, like member functions.
• A signal of one QObject may be connected to a slot of another QObject. If the signals and
slots are declared public, a third object can even do this connection.
The resulting operation of these constructs is that every time a QObject emits a signal, the slot
function of the QObject(s) it has been connected to will be executed immediately. Parameter values
are passed from the emitting object to the slot functions. Thus, emitting a signal is like a function call,
but with the very important difference that the emitting (calling) QObject does not need to know
which slot functions (if any) of which QObjects (if any) will be executed. This makes it possible to
design application-independent, reusable classes.
Note that all QWidgets are also QObjects with predefined signals and slots ready to be used. The
logic of the application is controlled by the way the developer decides to connect signals and slots
together. In addition, by sub-classing virtual functions found in Qt, the developer may customize the
look and behavior of existing widgets.
Qt’s signal-slot mechanism replaces the traditional callback mechanisms of older toolkits. An
important advantage of the signal-slot mechanism is that it is type-safe; mismatches between the
parameter types of the signal and the slot are handled gracefully. Such mismatches in callback
functions in other toolkits invariably lead to run-time failures (segmentation faults) and hard
application termination.
The typical use of the signal-slot mechanism is best illustrated by an example. For example, assume an
application design calls for a dialog box that gets closed when the user clicks its “OK” button. Using
Qt, the programmer will implement this using the classes QDialog and QPushButton. The
QPushButton class has a signal called clicked() that gets emitted when the user operates the
button. The QDialog class has a slot function called accept() that closes the dialog. Thus, the
programmer can achieve the desired functionality by simply connecting the clicked() signal of
the QPushButton object to the accept() slot of the QDialog object. The code looks like this:
Client processes communicate with the server to request regions of the display and to receive mouse
and keyboard events. In the regions it is allocated, the client directly accesses the display to provide a
GUI to the user.
The server and clients use shared memory to communicate the allocated regions, and to maintain a
software cursor if required.
Server architecture
The server maintains a set of regions, which change per client request as windows are created, moved,
resized, and destroyed. The set of regions resides in shared memory where it is read by the client as
drawing operations are executed.
The server connects to system devices such as a mouse and keyboard that produce events that are sent
to the appropriate clients. The mouse device can be a stylus or other pointer. The server generates a
device-independent mouse event and sends it either to the client that created the window containing
the mouse point, or the client, which has ‘grabbed’ the mouse. The server updates the hardware
mouse cursor, and the client and server maintain software cursor cooperatively. Stylus-operated
devices will generally not have a mouse cursor at all, but the gestures of the stylus are converted to
device-independent mouse events for standard processing by clients.
User interface elements such as the virtual keyboard are possible because the server process is also a
master client. The server therefore has access to all the GUI functionality available to clients. Usually
the server will only use this functionality for windows related to keyboard input and perhaps some
basic mechanism for launching client applications, but in very small embedded systems, the server
may be the only process. Any client application can be the master by setting a flag as it starts, but there
can of course be only one server for each display.
Client architecture
The API to which clients are written is the same standard Qt API found on Qt/X11 and
Qt/Windows. When a Qt/Embedded client uses the Qt API to draw a line, the Qt/Embedded library
accesses the display directly, whereas when a Qt/X11 client draws a line, the Qt/X11 library sends a
message to the X server, which does the actual drawing. Similarly, when a Qt/Windows application
draws a line, the Qt/Windows library calls the Win32 operating system to have the line drawn. In all
instances, the application code is the same, calling up the same standard Qt API line drawing
function.
The Qt/Embedded client library connects to the server process when the client starts and
communicates with the server for all operations which have global consequences such as changing the
display region covered by windows (which changes what regions are available to other clients),
manipulating the global clipboard and drag-and-drop properties, and receiving mouse and keyboard
events from the user.
It should be noted that for drawing operations, the client does not need to interact with the server
because it has an allocated region of the display to which it can freely write to display user-interface
controls, video clips, and other graphics. The client drawing functions are built on an architecture that
easily supports hardware accelerated operations, and has been test-targeted to Mach64 and Voodoo3
devices. The base drawing functions draw directly to the Linux frame buffer.
The Qt/Embedded client library handles all drawing operations, including text display and font
handling. It also handles window decorations (title bars, etc), which can be customized on a per-
window basis.
The client library has built-in support for Windows .FON files; TrueType, Type1, and BDF fonts;
and a memory-efficient bitmap font format for storing pre-rendered versions of such fonts. TrueType
and Type1 fonts can be displayed using anti-aliasing whereby text readability is improved by
smoothing.
Bitmap font files are formatted in such a way that they can be memory-mapped, unlike on X11, where
the server reads in the entire font. Similarly, TrueType fonts are rendered as required for each single
character, whereas on X11, many extra characters are rendered. For example, on X11, the character set
is divided into chunks of at least 16, so a heading such as "Welcome to Alcatel" renders almost all 52
upper and lower case characters, rather than nine.
Some functionality in the Qt API is implemented in a superior way on Qt/Embedded, such as the
anti-aliased text already mentioned, and full-color mouse cursors. These improvements are possible
because the client library has direct access to the display, unlike with X11 where the only drawing
operations that can be implemented efficiently are those defined in the X11 standard, which changes
very slowly. End-user applications for which portability to Qt/X11 and Qt/Windows is not required
can also leverage the direct access to implement very fast application-specific drawing.
Internationalization
Qt is designed to allow applications to use any language and character set. It is easy to switch
languages, even at run-time. The internationalization feature allows the application developer to
Unicode
Qt allows applications to use international (i.e. non-ASCII) character sets. For text operations, Qt
provides the QString class, which contains a text string in the 16 bit Unicode standard encoding. Qt is
16 bit clean throughout. The Qt kernel uses the QString class for all internal text operations, and it is
used in all API functions that take or return text parameters. This includes all text labels of widgets
such as labels on push buttons, menu items, content of line edits, etc.
QString is highly optimized, and in tests of moving real-world applications from 8 bit to 16 bit
strings, no significant performance penalty has been observed. This is not unexpected, since text
manipulation is not among the most demanding tasks performed by typical GUI applications.
Qt supports keyboard input and screen output of Unicode text, as provided by the underlying
window system. Screen output requires the appropriate font(s) to be installed. These fonts need not be
Unicode encoded as Qt provides codecs between Unicode and many of the common font encodings.
Custom codecs can also be added.
All application text I/O (e.g., to/from files) may be passed through a text codec, which translates
between the preferred local format and the Unicode standard format used internally. Codecs for a
number of commonly used locales are provided, as well as an API for implementation of custom
codecs.
Localization
Qt provides support for creating localized applications, such as applications that can choose at run-
time which language to display for all the user-visible texts. The choice may be made automatically
based on the user’s locale setting, or explicitly by the application. This can be achieved by presenting
the user with a language selection dialog on start-up. Building a Qt application that is prepared for
localization is straightforward: The programmer simply passes all user-visible texts through Qt’s
tr() (translate) function before passing them to Qt for display. For example, the non-localized
application code to make a push button display the text label “proceed” would be:
myPushButton->setText( “Proceed” );
The translate function will do a lookup in the current translation table, and return the text string
(translation) corresponding to the argument.
A handy aspect of the translate function is that if no translation table is installed, it will simply return
its argument. This means that a localization-prepared application will run just fine even if the
translation tables are not present. The behavior will be the same as if the application were not
prepared for localization. This is practical during application development when translation tables
often have not yet been produced, or for releasing the first version(s) of an application which is
planned to be localized in later versions.
Qt provides tools which assist the application developer to build and maintain the translation tables.
One tool, findtr(), searches the application source code for strings that need translation, and
produces a formatted text file with empty areas for the application translator to simply fill in the
required translations. Another tool, msg2qm(), converts these text files to the binary, hashed
translation table files that are used by Qt for lookup at run-time. A third tool, mergetr(), assists
in merging existing translation files when the application has been extended or modified so that new
strings that need translation have been added.
An example showing a translation to Japanese illustrates how easy Qt makes offering applications to
customers using any language. After having written the source using the tr() function for all
#: mywidget.cpp:28
msgid "MyWidget::E&xit"
msgstr ""
#: mywidget.cpp:41
msgid "MyWidget::Perspective"
msgstr ""
mywidget.po is copied to mywidget_jp.po and the Japanese signs inserted as appropriate, making it
look like this:
#: mywidget.cpp:28
msgid "MyWidget::E&xit"
msgstr " "
#: mywidget.cpp:41
msgid "MyWidget::Perspective"
msgstr " "
The only step needed now is to use the msg2qm() tool to generate the binary translation file,
mywidget_jp.qm, used run-time by Qt. The very same approach can naturally be repeated for any
language.
With the appropriate translation files and font sets installed, Qt allows the application’s language to be
changed run-time. The developer simply creates a QTranslator object, loads the appropriate
translation file and applies the translator to the current QApplication. In code, it looks like this:
All visible text will now be displayed using the Japanese character set, to the delight of the
application’s Japanese users. Localization is another example of a powerful, but often difficult to
implement concept made simple by Qt.
Layout management
When implementing the visual appearance of a GUI, one of the main tasks is to decide the positions
and sizes of the child widgets within their parent’s area. Although it is possible to hard-code static
coordinate values for all widgets, this approach is usually not satisfactory for anything but the simplest
applications, for the following reasons:
• Most applications will want to allow the user to resize the application window while still
keeping the window contents. This might produce unwanted results if the coordinates are
static.
• For localized applications, or applications where the contents of otherwise static widgets
can change dynamically at run time, suitable coordinate values cannot be known in advance.
• Similarly, applications that want to honor the user’s preferred font setting cannot know in
advance how much space will be required to display its widgets using that font.
• It is a time-consuming and tedious task for the programmer to tune the widgets’ positions
and sizes so that they align and give the desired aesthetic impression. Maintenance is also
demanding, since the whole layout must be manually re-implemented whenever widgets are
added or removed.
• QBoxLayout divides the available space into a stack of cells (horizontal or vertical).
In addition, custom layout manager classes may also be added. Note that instead of a child widget, a
cell may contain another layout manager object, which in turn manages other child widgets. Thus, by
building a nested structure of layout managers, automatic layout of very complex user interfaces can
be readily achieved.
• A widget may specify a minimum size it needs to display itself in a satisfactory manner. For
example, a push button will ask to not be made so small that it cannot paint its label and the
surrounding button frame.
• A widget may specify that it should not be stretched out more than its preferred size, or
that it should be stretched in only one direction. For example, a vertical scroll bar will specify
that it can be stretched vertically, but not horizontally, since the latter would ruin its visual
appearance.
All of Qt’s standard widgets provide sensible, run-time default values calculated using the widgets’
current contents and state for all the above-mentioned constraints. If the contents of a widget change
while the program is running, the layout will be automatically recalculated to fit the new size of the
widget.
• A stretch factor can be assigned to each cell to determine what ratio of the available,
superfluous space the layout manager will assign to it.
• The widths of the blank borders around and between the cells can be changed. Extra blank
space (stretching or non-stretching) may be added.
• The alignment (left/right/ top/bottom/center) of the child widget within the cell may be
specified.
• The maximum and/or minimum size of the child widget may be set explicitly.
By applying the above adjustments to the standard layout algorithm, virtually any layout behavior can
be obtained.
Customizing widgets
A central design feature of Qt’s widget system is extensibility. This is important since experience
shows that a fixed set of static widget classes cannot cover all the requirements of a real-world
application. GUI toolkit designers may attempt to foresee the various demands that applications may
Qt is designed to make it very easy to create custom widget classes. The application programmer
simply makes a new C++ class that inherits QWidget (directly or indirectly). There are no resource
files to be edited, or mandatory methods to implement (except for the constructor, as the C++ syntax
demands). Depending on what the widget shall do, the programmer can choose to implement any of
QWidget’s virtual methods, in order to receive events or customize look and feel.
Custom widgets have several powerful uses, including presentation of application data, tuning of
standard controls, and creation of custom controls.
Qt Virtual Framebuffer
An important utility available with Qt/Embedded is the Qt Virtual Framebuffer (QVFb). QVFb is
currently available on the X11 platform and makes it possible to run, test and debug embedded
applications right on the desktop. QVFb simulates the Linux Framebuffer and the user can specify
height, width and bit depths. In a marked where time to marked is crucial, QVFb is giving Qt
developers and important advantage.
QPE uses Qt/Embedded, so there is no need for an X11 server, extra client libraries, separate window
manager, or layer-upon-layer of toolkits. Although memory requirements vary somewhat on different
systems, the entire Qt Palmtop Environment requires about 2.5 MB of memory on x86 based
systems.
QPE is a complete Windowing System with Window Manager and an Application Launcher. In the
latest release, QPE 1.1, a simplified build system and improved development documentation allow
any developer to add their own applications to the QPE.
Several input methods are included making it easier for the end user to enter information:
• QWERTY layout virtual keyboard
• Opti layout virtual keyboard
• Pickboard – a popular mobile phone text input method
• Handwriting – a trainable handwriting input mechanism
• Unicode – displays all Unicode characters
and games:
• Mine Hunt
• Word Game
• Tetr*x
• Solitaire
• Tux
Trolltech currently has QPE running on Casio’s Cassiopeia and Compaq’s iPAQ as well as on
different development hardware. QPE is also available as a bootable floppy disk for PC. All are
available under the GPL license. To download the source or binaries for any of these platforms, please,
refer to http://www.trolltech.com/products/qt/embedded/qpe.html.
What many developers dislike is that most of these applications try to be too clever and lock their
users into their own technology and products. This might make sense from a strict business point of
view, but it is often not the optimal solution for the developer. For instance, in Microsoft Studio,
programmers are expected to use the accompanying text editor as well as the compiler. Traditionally,
IDE and RAD tools tend to offer poor support for integrating with the developer’s favorite text editor
or compiler.
Qt designer
With the release of Qt 2.2, Trolltech introduced the Qt Designer; an application designed specifically
to speed up the mundane and laborious tasks when constructing and maintaining graphical user
interfaces. The following is a list of what Qt Designer does:
• offers the user a point and click, Drag and Drop, WYSIWYG interface to user interface
creation and layout.
• provides easy access to all the standard widgets as well as the Layout Management
mechanisms available in Qt.
• generate C++ code. A separate tool, the User Interface Compiler, is offered which generates
C++ files from the User Interface files Qt Designer uses for persistent storage.
• force the developer into using a certain text editor, compiler or debugger. It gracefully
integrates with whatever tools the developer prefers working with.
From this it is clear that Qt Designer is not just another IDE. It is a specialized tool capable of
integrating with the application developer’s preferred development tools. This is done in a visual
manner, greatly speeding up the specific task of creating and maintaining graphical user interfaces. To
the developer, Qt Designer is a simple, yet very powerful tool.
Graphics
A QPainter operates on a paint device, and the application using the QPainter need not be concerned
about whether this QPainter is currently drawing on a widget or on a printer. The drawing API is
totally device independent. This is practical for many tasks. For instance, applications may use the
same drawing routine for screen output as for print output. This can be achieved by simply making
the drawing routine take the QPainter as a parameter, and then passing one QPainter operating on a
widget for screen drawing, and one QPainter operating on a printer for printer drawing.
QPixmap
A pixmap is an off-screen memory frame area, i.e. a two-dimensional array of pixel values. If an
application is going to display complex static graphics on screen, it makes sense to draw the graphics
into a pixmap, and then just draw the pixmap to screen later. This technique, known as double-
buffering, is more efficient since the complex drawing need only be performed once. It can also be
used to eliminate screen flicker. Qt provides fast bitblt() (bit block transfer) operations for
moving pixels between widgets and pixmaps.
Pixmaps are also handy for storing graphics to file for later retrieval, or other transfer of image data.
QPicture
A picture is a stored sequence of drawing operations. Pictures are very handy for storing graphics for
re-display at a different magnification level. Zooming in on a pixmap will only magnify the individual
pixels, but zooming in on a picture will recreate the drawing as if it had been drawn at that scale
originally.
Color handling
Qt provides a separate class for specifying color for drawing operations. Colors can be specified as
RGB or HSV values, or as a name from the web standard, such as “steelblue”, “green4”, etc. On
systems with limited color ranges like 8 bit displays, Qt automatically handles the allocation of colors
in the system palette so Qt-based programs need not do anything special to be prepared for running
on such systems.
For the fill style of polygons, ellipses etc., Qt provides the QBrush class. With this, the fill color and
pattern can be specified. QBrush provides a set of predefined patterns, but in addition, custom fill
pattern (specified as a pixmap) can also be used.
For the world transform, Qt supports a general transformation matrix. That is, all forms of coordinate
translation, scaling, rotation and shearing can be performed. A separate transformation matrix class is
provided, but QPainter also has convenience functions for specifying the most common
transformations directly.
For the view transform, Qt allows setting the origin and extent of the drawing window and the drawing
viewport. The drawing viewport determines the logical coordinate system, and specifying this to, for example,
1000 x 1000, gives the application programmer a 1000 x 1000 drawing area independent of the size of the
underlying physical device. The drawing window, on the other hand, determines the rectangle of the physical
device that the logical coordinates will be mapped down into.
All drawing operations provided by QPainter may also be performed with world and/or view
transformation applied, including text and pixmap drawing.
Clipping
QPainter allows clipping to a rectangle or a more general region composed of a set of rectangles,
polygons, ellipses, and bitmaps. The composition can be made as unions, intersections and/or
subtractions.
• How to align the text within the rectangle (top, bottom, flush left, center, flush right); and
• Whether Qt should break the text into lines to fit the width of the rectangle.
A separate class, QFont, is provided for specifying the font. All the fonts installed in the underlying
window system may be used for text drawing in Qt. A font may be selected by specifying any or all of
its name, size, weight (bold), slant (italic), and character set. Qt will provide the closest matching
available font. Font sizes can be given as logical (dpi) or pixel sizes. A number of international
character sets are supported, including ISO_8859-1 to ISO_8859-15 (Latin1 to Latin9), KOI8R, and
Japanese and various other Asian character sets.
Image handling
Qt supports input, output, and manipulation of images in several formats, including PNG, BMP
(Windows bitmap), XBM (X11 bitmap), XPM (X11 pixmap), PNM (P1-P6), and optionally GIF
(note that including GIF support may require patent licensing from Unisys). All these image formats
are supported on all platforms (e.g., BMP on both Windows and UNIX). Image formats are auto-
detected on reading.
The Qt ImageIO Extension library adds support for the JPEG format, and also allows application
programmers to add support for custom formats. The image formats added with the ImageIO
Extension become fully integrated with Qt’s image handling system, just like the internally supported
formats.
Once read into an application, an image is stored in a QImage object. This class provides an API that
allows manipulating the image data in a hardware-independent manner. This means applications
QImage supports images of 32-, 8-, or 1-bit depth. Images with other depths are automatically
converted to the next higher supported depth. For 8- or 1-bit deep images, a color palette is provided,
which also may be manipulated. Depth conversion methods are provided, including optional
dithering when converting to a lower depth.
For each pixel in a 32-bit deep QImage, an 8-bit value is stored for each of the red, green, blue and
alpha components. The optional alpha component may be used for custom image operations relating
to image transparency, blending, etc.
Qt also supports reading of animation image formats, with asynchronous (e.g. frame-by-frame)
reading for interleaved reading and display. The QMovie class provides easy handling of animations.
Canvas
The QCanvas class contains any number of QCanvasItems and has any number of CanvasView
widgets observing some part of the canvas. QCanvasItems represent drawing primitives such as
pixmaps, rectangles, lines and texts, and can be moved, hidden, and tested for collision with other
items. They have selected, enabled, and active state flags which subclasses may use to adjust
appearance or behavior.
A canvas containing many items is different than a widget containing many sub-widgets:
• Items are drawn much faster than widgets, especially when non-rectangular.
• Efficient item-to-item hit tests ("collision detection") can be performed with items in a
canvas.
Widgets of course offer richer functionality with respect to hierarchies, events, and layout.
Each canvas has a solid background and foreground, and all the items are drawn in between. Qt
provides a rich API, offering control of the appearance of each layer. QCanvas also simplifies
animation by enabling the user to control the speed and direction of movement of each QCanvasItem.
Finally, QCanvas offers collision testing. Using the API, it can easily be determined which, if any,
items collide with a point, a rectangle or with other items.
3D graphics
Qt does not itself offer 3D graphics functionality, but integration with 3rd party 3D libraries is
provided. Many Qt users employ these extensions to be able to offer exciting 3D solutions to their
clients and customers.
It should be noted that these integration packages do not depend on special support within Qt itself;
the ordinary Qt API provides the necessary general low-level access functions. Thus, it is possible for
application programmers to build custom integration packages to other libraries.
OpenGL
The Qt OpenGL Extension library provides integration with OpenGL. It allows the application
developer to build data display widgets where the contents are drawn using the native OpenGL library
HOOPS
HOOPS is a high-level, cross-platform, object oriented graphics subsystem that simplifies the design,
development and maintenance of high-performance, interactive 2D and 3D graphics applications. It is
a product of Tech Soft America, which offers a HOOPS-Qt integration package. More information
on HOOPS 3D can be found at www.hoops3d.com.
Some of Qt’s tool classes provide similar functionality to the C++ standard library and the STL.
However, Qt’s tool classes are preferable for most Qt-based applications, for the following reasons:
• Portability: the Qt classes are portable to a wide range of platforms and compilers. Many of
these platforms lack a functional and standard-conformant STL implementation. By using
the Qt classes, application programmers are relieved from relating to such portability issues.
• Cross-platform data exchange: Qt’s classes for data I/O provide platform- and architecture-
independence, so that even binary data can be successfully exchanged between one platform
and another. This is not the case with the standard I/O.
• Internationalization: Qt’s classes for text handling and I/O are Unicode-based and thus
fully prepared for internationalization. Again, this is not the case with the standard classes.
However, application developers may freely choose to use the standard library and/or the STL instead
of, or in combination with, the Qt tool classes; they may coexist in the same application without
problems, and data conversion between the tool sets is straightforward.
Qt provides OS-independent encapsulations of the most commonly used OS services. Thus, by using
the Qt API instead of the native OS API, Qt-based applications can be immediately re-compiled and
successfully executed on new platforms. This relieves the programmer from maintaining large
amounts of different, conditionally compiled (#ifdef’ed) code for the various platforms. It has the
added advantage of providing the programmer with a clean, object-oriented C++ API to the OS
services, instead of the native C API.
Low-level I/O
Qt provides an API for OS-independent file I/O. The file I/O class is a specialization of Qt’s general
I/O device encapsulation class. It provides low-level I/O, i.e., reading and writing of raw blocks of
bytes. Another specialization class provides I/O to a memory area. Custom encapsulations of other
I/O devices may be added in the same way. Thus, an application may use the same code for doing I/O
to files, memory buffers, and custom devices.
All the fundamental types (various precisions of integers and floating point values) and text strings
may be read and written. The stream format is independent of the OS and the CPU byte-ordering
(endianess), so the streams written on one OS architecture may be read on any other.
Most of Qt’s non-widget classes provide functionality for serializing their data to and from a binary
stream, so they can be stored efficiently for later retrieval.
The text stream can be set to use a specific encoding / codec in order to read or write text in a format
compatible with non-Qt applications.
Text classes
Qt provides two string classes. QString is a powerful string class for all kinds of text operations. It
operates with 16 bit Unicode characters. But for non-international applications, Qt provides the
QCString class. Seamless integration with the traditional C “char*” string is provided through
automatic conversions.
QString
QString uses sharing, meaning that copies of a QString object will share the same string data in
memory. The application programmer need not be concerned about the data sharing; if the
application modifies the contents of one of the copied objects, QString automatically makes a deep
copy of the string data, so that the contents of the other copies remain unchanged. Sharing saves
much memory and unnecessary copying.
QString provides all the usual string class functionality, like searching, replacing, conversion to and
from integer / floating-point values and various textual representations, comparison operators,
truncation, insertion, etc. It automatically allocates enough memory space for the contents, so the
programmer is relieved from managing this.
For advanced text searching, Qt provides a regular expression class. Strings can be matched against
regular expressions, and the position and length of the match is returned, so it is straightforward to
implement, for example, regular expression search and replace functionality.
QCString
For easy manipulation of non-internationalized text and classic C strings, in cases where the
conversion to and from QString’s 16 bit representation could become a performance issue, Qt
includes the QCString class which provides most of the same functionality as QString.
Collection Classes
Qt includes a full set of generic, template-based collection classes. These allow the programmer to
easily make things such as a stack class that operates on any Qt or programmer-defined class. The
major collection classes are:
• Dictionary: stores a key value along with each object, and provides fast (hashed) lookup
based on the key values.
• Cache: a dictionary with a programmer-defined limit to the total number and/or cost of
stored objects. When the limit is exceeded, the least recently accessed objects are discarded
from the collection.
• List: provides a double-linked list. For convenience, specialized List classes are provided for
commonly used collection types, such as Sorted List and String List.
For all collection classes, corresponding Iterator classes are provided. The Iterators allow traversal of
the entire collection independently of the collection’s normal access method.
Network Classes
Qt includes a set of classes offering cross-platform support for non-blocking socket-based
programming. The most important classes are briefly discussed below.
QSocket
This class can be employed to establish a non-blocking socket for TCP, UDP (a UNIX-domain
socket) or any other protocol family your operating system supports. It supports both binary and
ASCII mode and offers a rich API for communicating state and accessing its content.
QSocketNotifier
Once a QSocket is created, a QSocketNotifier can be created to monitor the socket. The
activated() signal is then connected to the slot to be called when a socket event occurs. There
are three types of socket notifiers and the type specifies when the activated() signal is emitted:
For example, if both reads and writes must be monitored for the same socket, two socket notifiers
must be created. Socket action is detected in the QApplication::exec() main event of Qt.
QServerSocket
This class is a convenience class for accepting incoming TCP connections. The port can be specified,
or QSocketServer can pick one, listening on just one address or on all the addresses of a machine.
QDns
Both Windows and UNIX provide synchronous DNS lookups; Windows provides some
asynchronous support too, but neither OS provides asynchronous support for anything other than
hostname-to-address mapping.
QDns rectifies that, by providing asynchronous caching lookups for the record types that modern
GUI applications are expected to need in the near future. The aim of QDns is to provide a correct and
small API to the DNS.
Threading
Qt offers cross-platform threading support.
QThread
A QThread represents a separate thread of control within the program It shares all data with other
threads within the process but executes independently in the way that a separate program does on a
multitasking operating system. Each thread starts executing in QThread::run() and dies whenever that
function returns.
MIZI Research, Inc., a leading Linux solution provider specializing in mobile Internet appliances
such as SmartPhoneT, PDAT, and WebPhoneT technology. MIZI is including Qt/Embedded with
their LINUETTE Linux for embedded devices.
PalmPalm Technology Inc., specializing in Embedded Linux, and Opera Software, a privately held
company headquartered in Oslo, Norway, have formed a strategic alliance with Trolltech for the Asian
wireless Linux market. The three companies are jointly developing the “Linux Total Solution for
Wireless Internet Appliance” for hardware manufacturers in the wireless Internet space. Linux Total
Solution for Wireless Internet Appliance consists of Opera’s “Opera for Linux” Web browser and
Qt/Embedded integrated with PalmPalm’s “Tynux,” a Linux Operating System optimized for the
wireless Internet.
Lineo, Inc., a leading embedded Linux solution provider, is collaborating with Trolltech to offer a
complete embedded Linux software solution to manufacturers of embedded devices. The combination
of Lineo's Embedix Linux software with Qt/Embedded provides customers with a valuable solution
for their embedded Linux software requirements at a low-cost while achieving high performance and
rapid time-to-market. Trolltech is a certified partner with Lineo's Partner Connect program.
NEC Electronics is adapting Qt/Embedded to run on NEC’s evaluation boards featuring the
VR4100™ family of 64-bit MIPS® RISC microprocessors. The VR4100 processors’ high speed, low
power consumption and high integration make them ideal for use in portable handheld systems. With
Qt/Embedded, NEC can offer attractive Linux-based GUIs to their customers.
Ericsson Home Communications is using Qt/Embedded as the GUI solution for their Cordless
Screen Phone, the Linux-based HS210. Ericsson made the decision to use Qt/Embedded due to its
low memory footprint, dedicated product architecture for embedded systems, and strong level of
support. In addition, Ericsson's familiarity with desktop Qt allowed an easy transition to
Qt/Embedded.