Contents |
This article teaches how to get started with Qt4 on the Maemo platform towards a code example. It describes how one can install Qt4 programming environment and execute a Qt4 application on Scratchbox.
Qt4 has been ported to Maemo platform by Qt4 Maemo developers team. Its main objective is to integrate Qt4 in Hildon, the main application framework of Maemo platform. For more information about the project, visit this page.
This section describes how you install Qt programming environment for Maemo platform.
You need to have Scratchbox and Maemo Diablo 4.X.X SDK properly installed on your host machine. If you still need some help to install such prerequisites on your environment, see this tutorial.
All you need is to install some packages on Scratchbox. After installing the Maemo development environment, there are two different targets: ARMEL, used for emulating applications for armel-based platforms, and X86-based platforms. For both cases, Qt4 development support is not installed by default. It is necessary to install Qt4 and also the libraries (in both the targets).
To start with, we need to add "extra" and "extra devel" repositories to Scratchbox apt-get sources and install the Qt libs.
To modify /etc/apt/sources.list file on a terminal, you need to change the attributes from read-only to read-write by excuting following lines.
maemo@maemo:/etc/apt$ sudo chmod go+w sources.list maemo@maemo:/etc/apt$ ls –l sources.list
To open sources.list and save changes, you can excute these lines on terminal.
maemo@maemo:/etc/apt$ vi sources.list
In vi mode, using direction keys to specify the location and press Insert to entering following lines. Press Esc to finish the entering progress and using command “:wq” to save your changes and quite vi mode. After editing you can retract write authority with following line to protect the file.
maemo@maemo:/etc/apt$ sudo chmod go-w sources.list
Paste the following lines into your /etc/apt/sources.list file on Scratchbox:
deb http://repository.maemo.org/extras/ diablo free non-free deb-src http://repository.maemo.org/extras/ diablo free deb http://repository.maemo.org/extras-devel/ diablo free non-free deb-src http://repository.maemo.org/extras-devel/ diablo free
First execute this line to ensure that your connection to internet in Linux VM/OS is available.
[sbox-DIABLO_X86: ~] > export http_proxy=http://xxx.xx.xxx:8080
Then, we can the packages which are necessary to provide Qt4 programming environment: libqt4-core, libqt4-gui and libqt4-dev. Execute the following lines on Scratchbox shell:
[sbox-DIABLO_X86: ~] > apt-get update [sbox-DIABLO_X86: ~] > fakeroot apt-get install libqt4-core [sbox-DIABLO_X86: ~] > fakeroot apt-get install libqt4-gui [sbox-DIABLO_X86: ~] > fakeroot apt-get install libqt4-dev
Great! We can start developing Qt applications on Maemo platform.
In this section, we provide an example of Qt application. We will show you how to compile and execute it on Scratchbox.
There is a verified path that qt projects can compile and execute properly. Otherwise some uncertain problems will occur. To avoiding such cases, we create our “.cpp” file in such direction or its sub-folders: /scratchbox/users/maemo/home/maemo/.
1 #include <QApplication>
2 #include <QLabel>
3
4 int main(int argc, char* argv[]) {
5 QApplication app(argc,argv);
6 QLabel *label = new QLabel("Hello World!");
7 label->show();
8 return app.exec();
9 }
At lines #01 and #02, we insert two header files which contains definitions for QApplication and QLabel type. At line #05, we create a Qt application and then a label which is inserted into the Qt application just created. Finally, the label is shown (line #07) and the main GUI loop is started (line #08).
All the tools used to build Qt4 applications for Maemo platform are available on Scratchbox. Therefore, we follow the standard Qt way to compile our application:
[sbox-DIABLO_X86: ~] > qmake -project [sbox-DIABLO_X86: ~] > qmake file.pro [sbox-DIABLO_X86: ~] > make
The first line create a *.pro file, which helps to build the application. We then generate the Makefile (on second line) which is used to build your project. Finally, we compile the project with make.
To execute the application on Scratchbox, you need to start Hildon application framework on Scratchbox. This link shows how you can do that.
Using following line to activate Hildon application framework.
[sbox-DIABLO_X86: ~] > af-sb-init.sh start
The following line executes the application on Scratchbox:
[sbox-DIABLO_X86: ~] > ./hello_world_qt
We obtain the following result. However, it does not look like a Hildon theming application. For instance, the background is dark-gray and the fonts are small. It is necessary to execute the application using run-standalone.sh script in order to change to correct look-and-feel. Now, try again:
[sbox-DIABLO_X86: ~] > run-standalone.sh ./hello_world_qt
But remember: run-standalone.sh script is only available if you run the application from the Scratchbox console or inside Internet Tablet.