Develop for the Nokia N900 and Maemo 5 OS!
Learn how to program the next-generation smartphone-come-internet tablet, the Nokia N900…
2. Installing Qt 4.5
We will be using the Qt 4.5 toolkit to develop our Maemo application. We need to install the Qt toolkit in the Scratchbox environment. To do that, first open the Scratchbox environment using the following command:
Now perform the following commands to install the Qt toolkit:
[sbox-FREMANTLE_X86: ~] > fakeroot apt-get install libqt4-gui libqt4-dev
You can check the installed Qt version by using the following command:
[sbox-FREMANTLE_X86: ~] > qmake -v
3. Qt Introduction
Qt is a cross-platform application and UI framework. It is probably the best C++ toolkit out there. A brief description of what Qt is and what it can do is available in this article, ‘Linux, supercharged development environment’, starting on page 60 of issue 84. So go and take a look at that, if you like, and then come back to this page.
The Qt toolkit has been designed around a few key concepts…
Use of native APIs to render UI
Qt makes use of native UIs on different platforms to draw different Qt controls. So when you are writing a cross-platform application, you will always get a native look and feel of the platform you are running on. For instance, the Windows version of Qt uses Win32 libraries, while the Mac version uses Mac OS X native Cocoa libraries to draw different UI elements. This also allows you to call platform-specific procedures from the Qt applications.
Meta object compiler (moc)
moc is a tool which is run on a Qt program. It interprets certain macros from Qt code as annotations and generates additional C++ code with meta information about the classes used in the program. moc files are generally in the form of ‘moc_original_file_name.cpp’. You should not directly edit the moc files as these files are overwritten based on the changes made in the original file.
qmake is a Qt build which enables developers to develop cross-platform-compatible makefiles which are compatible with the current platform. qmake works against
a project file to generate platform-specific makefiles. qmake is also intelligent enough to generate its own project files.
$ qmake -project // Generates the project file
$ qmake // Generates the make file
Signals and slots
Signals and slots is a language construct which is designed to simplify the communication between the objects. GUI programming is mostly event-driven and conventionally uses callbacks. A popular example of the framework using callbacks is GTK (GIMP Toolkit). Callbacks require lot of boilerplate (repetitive) code. The concept is that controls (also known as widgets) can send signals containing event information which can be received by other controls using special functions known as slots. For example, when a button is clicked, it emits a ‘clicked()’ signal. Signals do nothing alone, but once connected to a slot, the code in the slot will be executed whenever the signal is emitted.