×
Namespaces

Variants
Actions
Revision as of 16:41, 6 September 2009 by bogdan.galiceanu (Talk | contribs)

Archived:Getting started with Qt for Maemo

From Nokia Developer Wiki
Jump to: navigation, search
{{{width}}}
Featured Article

Contents

Introduction

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.

Installation

This section describes how you install Qt programming environment for maemo platform.

Prerequisites

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.

Getting packages

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 besed 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 excute 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.

Creating a simple application

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).

Building

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.

Executing

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

Hildon application framework

The following line executes the application on Scratchbox:

 [sbox-DIABLO_X86: ~] > ./hello_world_qt
 

Qt4 maemo application

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
 

Qt maemo application 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.

117 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×