Quest for PDA Utopia: Qtopia?

by Timotej Ecimovic

Like most geeks nowadays, I've been contemplating buying a PDA. I own a desktop and a laptop, but there's still that urge of having something in my pocket to play with wherever I go. I am not a big fan of Microsoft operating systems, so the WinCE platform wasn't really in play. I decided against the usual choice, a Palm, because it seemed too expensive for its limited hardware. For a while I toyed with idea of getting a Compaq iPAQ and installing Linux on it. Again, I decided I was too old and too lazy for compiling and recompiling drivers, adjusting applications and making the whole thing work, so I didn't get it after all.

And then, just as I was about to give up on my mission, Sharp came through with its Zaurus SL-5000D, a stylish, light, Palm-shaped device with a tiny pull-out keyboard, impressive hardware and a very reasonable price. And the best part: it is based on open-source embedded Linux. Trolltech, the company behind Qt, developed a windowing system and graphic user interface for Zaurus, called Qtopia, from scratch. To my satisfaction, I found that Qtopia provides a high-level graphical interface on top of Qt/Embedded, which directly interfaces with the framebuffer hardware device. Qtopia also provides an application layer with several services for application development. It was a dream come true and a neat present wrapped in one.

Road to Utopia

Qtopia hasn't just appeared from thin air. Trolltech already has made a name with its kick-ass GUI development toolkit, Qt, which has become the tool of choice for such undertakings as the open-source KDE desktop envrironment and also the selected library for many commercial applications. With the experience gained from that, they decided to step into the PDA arena with Qtopia, their own PDA environment, which is OS- and platform-independent, just as Qt is. Qtopia is not a direct competitor for Microsoft's WinCE, which is the operating system as well. But Qtopia is a perfect choice for vendors that have PDA hardware and an operating system, but need a graphical user interface.

And here's where Sharp comes into play. Sharp recently has unveiled its hot Zaurus SL-5000D PDA. The D stands for Developers' edition, because the device is not yet available for general consumers. They made a bold decision to equip the wonder with embedded Linux (from Lineo) for the operating system and use Qt/Embedded with Qtopia on top of it for the graphical user interface.

Quest for PDA Utopia: Qtopia?

Figure 1. Qtopia Desktop

The purpose of this article is to get you started on the road to developing applications for Qtopia. The first steps are usually the hardest. Hopefully the information presented here will help you with the initial struggle of getting over the hump of setting up the development environment and getting through the first sample application. We will not cover the complete set of Qtopia classes, nor will we learn details of Qt toolkit for developing GUIs under Qtopia. Those subjects, unfortunately, are outside the scope of a magazine article, and besides, there is free documentation available on the Web.

Developers Needed

You know how the Volkswagen folks put it: Drivers Wanted. Well, the same goes for Zaurus. The one thing that Qtopia lacks, in comparison to the WinCE environment and ubiquitous Palm devices, is applications. But Qtopia comes with these basic applications:

  • Personal Information Management suite: address book, to-do list and appointment calendar that can be synchronized with the Qt/Desktop client.

  • Internet suite: contains the Opera web browser and e-mail client with POP3 and SMTP support.

  • Multimedia application: player (MPEG-1/2 and MP3) and image viewer.

  • Miscellaneous : calculator; text editor; international clock with time zones; a package manager, used for installation and removal of software packages; and utilities, including the system info display and tools for setting time, power conservation features, network configuration and so on.

  • Games: contains clones of classics such as Asteroids, Solitaire and Minesweeper. Nice additional surprises are Scrabble, Mindbreaker, the Chinese game of Go and a few others.

  • Within the system application group is the terminal, giving you access to the bash shell and the file manager for traversing the directory structure.

Synchronization on the desktop side is done with Qt/Desktop. And here's a bit of irony: it only runs on the Windows platform, and I was not particularly impressed with it. The connection to the PDA was dropping randomly, and every now and then I had to restart Qt/Desktop to reestablish connection. But all is forgiven when Zaurus sits in a cradle connected to the USB port of a Windows 2000 host and gets its own IP address. A special driver is installed on the Windows 2000 host to support this additional network interface. According to Trolltech, the synchronization software will be available for Linux too when the final version of Qtopia is released.

Qtopia is still a very young platform, and applications are scarce. There is a good collection of packages for embedded Linux that will run on the Zaurus, such as Perl, Python, command-line tools and even server software, such as the Telnet dæmon and a web server (imagine hosting a web site on a PDA). But developers of additional GUI applications for Qtopia are still direly needed. Trolltech is jump-starting this with a worldwide contest for Qtopia applications that offers a grand prize of $10,000 US.

Developer Setup

Those of you who will welcome the challenge of developing applications for Qtopia will need a few tools to get the job done.

Qtopia SDK is the core part of the development environment. Trolltech is providing the SDK for Linux that contains everything you need for development of Qtopia applications on the desktop. SDK is available as a free preview for owners of the Sharp Zaurus SL-5000D or the entrants of the Qtopia programming contest. You can get it in the form of an RPM file, and after you install it on your desktop Linux box, you get the following important tools:

  • qvfb (virtual framebuffer for X11): this is the X Window System application that gives you the window for running and testing your Qtopia applications. Qt/Embedded will connect to this program to display all the content.

  • Qt/Embedded and Qtopia libraries: the core libraries for Qt/Embedded version 2.3.2 and Qtopia version 1.5.0.

  • qpe (qtopia executable): the central qtopia executable, which deals with all user interface issues.

  • mkipks: packages for creating ipk files for deployment in a PDA.

Besides Qtopia, these specific tools are typical Qt development support applications:

  • designer: the application used in designing widgets.

  • tmake: cross-platform Makefile generator.

  • moc: meta-object compiler for Qt C++ extensions.

  • uic: user interface compiler that generates C++ code from XML files.

With these tools, you are all set to start developing on Linux. You can develop, compile and test your applications as long as you have the GNU C++ compiler, g++, handy. If you don't own a PDA and can't test native PDA code anyway, you can stop here. But if you are an owner of the Sharp Zaurus, there is one more thing you will need: the ARM Linux cross-compiler toolchain.

Now, we're in for some serious geekish stuff! The cross compiler enables you to compile executable machine code for a particular processor on a machine with an entirely different processor. In our case, we will be compiling code on an Intel Pentium processor-based system for the PDA that has a StrongARM type processor, such as the Zaurus or an iPAQ. The cross-compiler toolchain package gives you replacements for gcc/g++ compilers, called arm-linux-gcc and arm-linux-g++. The package can be retrieved from ftp://ftp.handhelds.org/pub/linux/arm/toolchain/ as an RPM or .tgz file, and the executables can be used directly. Just use the arm-linux tools instead of your regular ones, and your executable will no longer be for the x86 Linux, but for StrongARM Linux.

Development Cycle

Assuming we have all the tools mentioned above, we now can attempt to build our very first Qtopia application. It will not be very functional, but hey, the purpose here is not to create the next killer app for you, but rather to give you tools so you will be able to create one yourself. As you will notice, most of the work actually will be with the Qt toolkit itself, but within the Qtopia environment. In order to understand this example, you either have to be familiar with the concepts of the Qt toolkit, or you can pick it up quickly if you have ever worked with any other GUI toolkit. Obviously, before you start building CAD/CAM software or 3-D games for the Qtopia, you'll have to become a Qt expert.

Example Application

Let's create the application that will count the number of times a button is clicked and store this counter to the permanent storage using Qtopia mechanism. Such a task should be simple enough for a beginner. First, we create the header file for our class definition, as shown in Listing 1.

Listing 1. Creating the Header File

We have defined a simple widget creating a text area (QMultiLineEdit object) and two buttons, the Work button and the Quit button. Two slots will be associated with the buttons. The Q_OBJECT definition, which basically defines the class as being a Qt object, requires that the meta-object compiler has to be used to generate additional files. Now let's create the C++ source code for the application and save it to the file hello.cpp (see Listing 2).

Listing 2. Creating the C++ Source Code

We have created the buttons, the multiline edit field and have connected the slots with the clicked() signals. For those who have never worked with the Qt toolkit, it is good to explain that besides standard callbacks, Qt supports a slot/signal mechanism for connecting GUI actions with the functionality. Any object can contain slots and signals, and any object's signals can be connected to any other slots, triggering the action. Calls to the connect() function above can read: ``When ExitButton is clicked, call the class quit() method, and when WorkButton is clicked, call the class work() method.'' The Config Qtopia class is used for saving the state of the application. We are using the setGroup method to set the namespace for our property, and then readNumEntry() and writeNumEntry() to read and write the counter value to the permanent storage. Of course, we also need main() inside a main.cpp file. The main function typically follows the standard pattern:

#include "hello.h"
#include <qpe/qpeapplication.h>
int main( int argc, char ** argv ) {
    QPEApplication a( argc, argv );
    Hello h;
    a.showMainWidget( &h );
    return a.exec();
}

Instead of QApplication(), which is used in desktop Qt applications, we use QPEApplication(). The main() function creates the main widget, associates it with the application and dives into the event loop.

The last thing that remains is compiling and executing our program. For compiling, let's use tmake, which is provided with Qtopia. The profile for the application will reside in a file called hello.pro and might look like this:

TEMPLATE        = app
CONFIG          = qt warn_on release
HEADERS         = hello.h
SOURCES         = main.cpp hello.cpp
INCLUDEPATH     += $(QPEDIR)/include
DEPENDPATH      += $(QPEDIR)/include
LIBS            += -lqpe
TARGET          = hello

Refer to the tmake documentation for an explanation, but for our purpose, it is enough to know that we can create a Makefile by running the following commands (assuming you have installed Qtopia in the /opt/Qtopia directory):

export TMAKEPATH=/opt/Qtopia/tmake/lib/qws/
linux-generic-g++
tmake -o Makefile hello.pro
With the Makefile, the application can be built simply by running make.

Let's bask in our glory now. For testing the application, we first need the virtual framebuffer, where the application will reside. Let's run it:

qvfb &

A little window should pop up now. This is your framebuffer. Now we run the application:

./hello -qws
The -qws argument is specifying that the program run as a Qt/Embedded server. Qt/Embedded works by having one program act as the server, similar to a window manager. This application executes other ones. For testing purposes, we don't need to run the default server called qpe, so we will just use our application in a server mode.
Quest for PDA Utopia: Qtopia?

Figure 2. Our Counter Application inside the qvfb

I hope this will get you on a right track for developing for the Qtopia environment. All you need is a Linux box and the SDK. The PDA can come later. With the SDK you also get extensive documentation about other Qtopia classes. We have used just two in our example, the Config class and the QPEApplication, though there are others. Let's review few of the most interesting ones:

  • Network class, which simplifies TCP/IP development through an abstraction of a Network layer.

  • AlarmServer, which deals with setting and ringing the alarms.

  • Database, DatabaseView and Record, which deal with the database abstraction layer for permanent storage.

  • QCopChannel and QCopEnvelope, which are channel-based, interprocess communication mechanisms. The QCop messages are used for starting programs and waking them up from the passive state.

  • QLibrary, the abstraction layer for the shared library manipulation.

You will encounter others when you get into more serious coding. They're well documented, so I won't bore you with them in this article.

Compiling for PDA

If you happen to own a Zaurus, and you would like to see your application actually run on it, you will need to engage the ARM Linux cross-compiler toolchain to compile it. If you're using the Qtopia SDK, change your TMAKEPATH environment variable:

export TMAKEPATH=/opt/Qtopia/tmake/lib/qws/
linux-sharp-g++

Now, build the application:

tmake -o Makefile hello.pro
make clean
make
Your executable should now be compiled for ARM Linux.
Conclusion

The past decade has seen the geeks rally behind Linux and make it one of the most important operating systems ever. Having won this battle, we can transfer our energy into the mobile arena. Qtopia on embedded Linux seems like a very promising PDA environment. And just maybe, we can make embedded Linux one of the most important PDA operating systems as well.

Both physicists by trade, Manica Son is currently a freelance writer, and Timotej Ecimovic is a technologist working with Razorfish. They have been married for almost four years and moved to Boston from their native Slovenia three years ago. Both share enthusiasm for Linux and writing human as well as computer languages. Manica can be contacted at mancason@yahoo.com and Timotej at tecimovic@hotmail.com.

Load Disqus comments

Firstwave Cloud