Yesterday I explained how to install the Maemo 5 SDK on Fedora 12 and launch the N900 phone emulator. Today we are going to configure the development environment for QT and deploy a “Hello World” application to the Nokia N900 emulator.
To have a better understanding of the whole platform, including GTK+ programming that we are not going to use, Nokia has a series of good videos:
Scratchbox
When we installed the SDK yesterday, I told you that a lot of files went into a /scratchbox repository. For the sake of clarity, it’s a good idea to explain what Scratchbox is. Directly stolen from Scratchbox’s website we can read that “Scratchbox is a cross-compilation toolkit designed to make embedded Linux application development easier. It also provides a full set of tools to integrate and cross-compile an entire Linux distribution.”
The N900 has an ARM Cortex-A8 processor and we are developing on x86, that’s why Scratchbox is used…cross-compile our code to the ARMEL target so it’s deployable on the real phone. In the SDK, Scratchbox is used as a completely autonomous Linux system living in /scratchbox; so all the packages that we are going to install in this OS won’t affect Fedora in any way.
Repositories management in Maemo 5
As Maemo 5 is “just” a modified Debian, so it is using the same tools to manage packages: apt and friends. As with any Linux OS based on packages you can add repositories to get software. In Maemo 5, the repository structure is exactly what we had before Fedora 5/6: a “base” repository managed by Nokia and “extra” repositories managed by the community.
So…repositories. By default only a couple of select repositories related to the SDK and Nokia’s proprietary binaries are enabled. What we want is to enable the community “extra” repositories so we can play with other applications. It’s managed exactly like in yum: edit a text file and update the repository list.
The first thing to do is to login to Scratchbox:
[Steven@x301 ~]$ /scratchbox/login
Welcome to Scratchbox, the cross-compilation toolkit!
Use ‘sb-menu’ to change your compilation target.
See /scratchbox/doc/ for documentation.
Now edit the repositories list, the links to the extra repos are available on http://repository.maemo.org. We are going to add extras only, add extras-testing and extras-devel at your own risk…. Note that “fremantle” is Maemo 5′s name:
[sbox-FREMANTLE_X86: ~] > vim /etc/apt/sources.list
#Extras
deb http://repository.maemo.org/extras/ fremantle free non-free
deb-src http://repository.maemo.org/extras/ fremantle free
#Extras Testing
#deb http://repository.maemo.org/extras-testing/ fremantle free non-free
#deb-src http://repository.maemo.org/extras-testing/ fremantle free
#Extras Devel
#deb http://repository.maemo.org/extras-devel/ fremantle free non-free
#deb-src http://repository.maemo.org/extras-devel/ fremantle free
Now update apt’s local cache:
[sbox-FREMANTLE_X86: ~] > fakeroot apt-get update
Install QT in Scratchbox
At the moment, QT 4.5 is the default version shipped with the 1.1 firmware, QT 4.6 will come with the 1.2 firmware release as far as I know and it contains many changes to be better on Maemo. If you want to play with QT 4.6, you can install it from extras-devel, we are going to stick with 4.5 at the moment. The installation is dead simple:
[sbox-FREMANTLE_X86: ~] > fakeroot apt-get install libqt4-gui libqt4-dev
Deploy your first QT application in the emulator
I’m not going to start a QT course here, but there is a lot of online material available for that including the first edition of the “C++ GUI Programming with Qt 4” book. I have ordered the second edition on Amazon and it’s really great.
So, let’s create our first QT application, compile it and run it on the emulator! You may have noticed that the SDK also installed an “sbhome” directory on your desktop. This is your user’s home directory in Scratchbox. So it’s a filesystem the Maemo 5 emulator has access to…that’s why it’s a good place to store your QT projects. Go to this directory and create a HelloWorld folder. Create a “HelloWorld.cpp” file with the following content in it:
#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel(“Hello World”);
label->show();
return app.exec();
}
Thanks to QT, these lines will magically generate a complete GUI application. Our source code is ready, now we need to create a QT project from it and compile it. For this, we need to be in Scratchbox:
[Steven@x301 ~]$ /scratchbox/login
[sbox-FREMANTLE_X86: ~] > cd HelloWorld/
[sbox-FREMANTLE_X86: ~/HelloWorld] > qmake -project
[sbox-FREMANTLE_X86: ~/HelloWorld] > ls
HelloWorld.cpp HelloWorld.pro
[sbox-FREMANTLE_X86: ~/HelloWorld] > qmake
[sbox-FREMANTLE_X86: ~/HelloWorld] > ls
HelloWorld.cpp HelloWorld.pro Makefile
[sbox-FREMANTLE_X86: ~/HelloWorld] > make
g++ -c -pipe -O3 -g -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/targets/FREMANTLE_X86/usr/share/qt4/mkspecs/linux-g++-opengl -I. -I/targets/FREMANTLE_X86/usr/include/qt4/QtCore -I/targets/FREMANTLE_X86/usr/include/qt4/QtGui -I/targets/FREMANTLE_X86/usr/include/qt4 -I. -I. -o HelloWorld.o HelloWorld.cpp
g++ -Wl,-O1 -o HelloWorld HelloWorld.o -L/usr/lib -Wl,-rpath-link=/usr/lib -lQtGui -lQtCore -lpthread
Now run the emulator GUI from your desktop and run the program from Scratchbox:
[sbox-FREMANTLE_X86: ~/HelloWorld] > run-standalone.sh ./HelloWorld
It works! As you can see, QT has done quite some magic for us: the application already looks like a native Maemo 5 application and has a close button!
Next
In the next article, we are going to create a Debian package for the ARMEL target and deploy the application on the phone. Then we will have completed the development chain overview.

Scratchbox is not N900 emulator – it just gives you possibility to run Maemo5 environment.
Yep, it’s a confusion I made while writing the text, mainly because the N900 is the only widely available device running Maemo 5.
Hi,
I would like to create my applications and copy it to a mimSD card, stick it in my phone and run the app. Is that possible? If so how or can you point me in the right direction?
Thanks
You can run the application from the command line this way IMO, but it you want an icon to show up in your Maemo interface you need to create a correct package and install it. You should really ask your question on the maemo forums at maemo.org…