Archived:Getting started with Qt for Maemo
Template:Archived Template:ArticleMetaData Template:FeaturedArticle
Introduction[edit | edit source]
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.
Installation[edit | edit source]
This section describes how you install Qt programming environment for Maemo platform.
Prerequisites[edit | edit source]
You need to have Scratchbox and Maemo SDK properly installed on your host machine. If you still need some help to install such prerequisites on your environment, see Maemo 4 tutorial or Maemo 5 SDK installation
Enabling additional repositories[edit | edit source]
To start with, we need to add "extras" and "extras devel" repositories to Scratchbox apt-get sources. Note that this step is mandatory only for Maemo 4, Maemo 5 has Qt as part of main distribution.
To modify /etc/apt/sources.list file on a terminal, you need to change the attributes from read-only to read-write by executing the 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 execute these lines on terminal:
maemo@maemo:/etc/apt$ vi sources.list
In vi mode, use direction keys to specify the location and press Insert to enter the following lines. Press Esc to finish and type in command “:wq” to save your changes and quit vi mode. After editing you can retract write capability with the 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:
Maemo 5:
deb http://repository.maemo.org/extras/ fremantle free non-free deb-src http://repository.maemo.org/extras/ fremantle free deb http://repository.maemo.org/extras-devel/ fremantle free non-free deb-src http://repository.maemo.org/extras-devel/ fremantle free
Maemo 4:
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
If you are behind a firewall and need to use an http proxy, execute this line (modify for the correct IP address) to ensure that your connection to internet in Linux VM/OS is available.
Getting packages[edit | edit source]
All you need to get started 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).
[sbox-DIABLO_X86: ~] > export http_proxy=http://xxx.xx.xxx:8080
Then, we can install 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-dev
Great! We can start developing Qt applications on Maemo platform.
Creating a simple application[edit | edit source]
In this section, we provide an example Qt application. We will show you how to compile and execute it on Scratchbox.
There is a certain path where qt projects can compile and execute properly. Otherwise problems may occur. To avoid such cases, we create our “hello.cpp” file in such a directory 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("Hello World!");
7 label.show();
8 return app.exec();
9 }
At lines #01 and #02, we insert two header files which contain definitions for QApplication and QLabel classes. At line #05, we create a Qt application and then a label which is inserted into the Qt application we just created. Finally, the label is shown (line #07) and the main GUI loop is started (line #08).
Building[edit | edit source]
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 [sbox-DIABLO_X86: ~] > make
The first line creates 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.
Executing[edit | edit source]
To execute the application on Scratchbox, you need to start Hildon application framework on Scratchbox. This link shows how you can do that.
Using the following line to activate Hildon application framework:
[sbox-DIABLO_X86: ~] > af-sb-init.sh start
Hildon application framework in Maemo 4
The following line executes the application on Scratchbox:
[sbox-DIABLO_X86: ~] > ./hello_world_qt
Qt application running in Maemo 4 emulator
Qt application running in Maemo 5 emulator
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 get the correct look-and-feel. Now, try again:
[sbox-DIABLO_X86: ~] > run-standalone.sh ./hello_world_qt
Qt application running in Maemo 4 emulator with Hildon theme
Qt application running in Maemo 5 emulator with Hildon theme
But remember: run-standalone.sh script is only available if you run the application from the Scratchbox console or inside Internet Tablet.
pt:Archived:Primeiros passos, em Qt para Maemo