Qt4 development

(Maemo Style: update documentation links)
m (Showing the status bar: use <code>)
Line 84: Line 84:
Hildon applications don't have a status bar. Qt for Maemo hides the status bar by default.
Hildon applications don't have a status bar. Qt for Maemo hides the status bar by default.
You can show it again by using method ''statusBar()->show()'' in your class derived from QMainWindow.
You can show it again by using method <code>statusBar()->show()</code> in your class derived from <code>QMainWindow</code>.
===Using the Kinetic Finger Scrolling (cf Gtk's PannableArea)===
===Using the Kinetic Finger Scrolling (cf Gtk's PannableArea)===

Revision as of 13:25, 2 June 2010

IMPORTANT: This page is for Fremantle PR 1.2 using Qt 4.6. If you want to develop for Diablo or use Qt 4.5 please have a look at the Qt4 Hildon Legacy Page.



To develop with Qt for Maemo, a working SDK installation is required. There are instructions on how to install the Maemo SDK, and you can watch the Maemo SDK in action. Alternatively, you may want to try MADDE, a cross-platform Maemo development tool, available as a technology preview.

Getting started

To start to develop with Maemo Qt, we need to install the Maemo SDK.

Qt 4.6 is available in public Fremantle repository since the release of PR1.2. To upgrade older Scratchbox targets to use the latest packages, execute the following commands (inside Scratchbox):

fakeroot apt-get update
fakeroot apt-get dist-upgrade

You can install Qt with the command:

fakeroot apt-get install libqt4-dev

GIANT WARNING: Your device might not be running Qt 4.6, but your Scratchbox probably is. Make sure that your N900 has the PR1.2 update by checking the software version (found in Settings->About product. PR1.2 is version 10.2010.19-1.

How to compile a Qt application in Scratchbox

Qt applications are usually built using QMake. Project like KDE instead replaced QMake with CMake for more flexibility.


QMake is a tool from Trolltech that helps simplify the build process for development project across different platforms

You can build your Maemo Qt application in 3 simple steps:

  1. Generating project file (Required if there is no .pro file into the app source tree)
    qmake -project
  2. Generating Makefile from the QMake project file:
    qmake file.pro
  3. make


CMake projects usually have a CMakeLists.txt file instead of:

  1. .pro file used by QMake projects
  2. Makefile.am used by Autotools projects (standard in Unix/Linux)

Using CMake to build the project is extremely easy. In the directory containing CMakeLists.txt, supply the following two commands, where path is the path to the source code.

cmake path

Note: CMake is not installed by default in Scratchbox. You can install it with the command:

fakeroot apt-get install cmake

Running a Qt application in:


Diablo and Fremantle Qt applications can run on the device as in Scratchbox.

First step to run a Qt application is starting the SDK UI:

  1. Run Xephyr. It is able to run a X Server inside another X Server.
    Xephyr :2 -host-cursor -screen 800x480x16 -dpi 96 -ac -kb
  2. Set display for application that runs inside Scratchbox:
    export DISPLAY=:2
  3. You can now run the SDK UI. A Diablo or Fremantle desktop will appear in your Xephyr window:
    af-sb-init.sh start
  4. Now you are ready to run any Maemo or Maemo Qt application with:
    run-standalone.sh ./qtapps

Note: run-standalone.sh sets some variable needed by Qt to use the Hildon style.


Maemo Qt applications are Linux binaries. They can run on the device without any problem if you copy them to "partitions" mounted with exec flag. (for example, /home/user or /opt in Fremantle).

Fore example, if we want to run quassel (Qt IRC Client) we have to launch it with:

su -c ./quassel user

Porting Qt applications to Maemo

Porting a Qt desktop application to Maemo requires very little effort. This is because the Maemo Qt libraries will take care of giving the Hildon look & Feel and enabling the virtual input methods for your application.

Overriding the Qt Maemo changes

Maemo Style

Hildon Style is the default Qt application style. Other style available are:

Qt application can use other Qt styles;

Showing the status bar

Hildon applications don't have a status bar. Qt for Maemo hides the status bar by default.

You can show it again by using method statusBar()->show() in your class derived from QMainWindow.

Using the Kinetic Finger Scrolling (cf Gtk's PannableArea)

See Finger Scrolling

Adding Maemo changes to a Qt Application

Some methods of Qt for Maemo are not available in the "standard" Qt libs, so a Qt application with specific Maemo Qt code can't be built outside the Maemo SDK. To avoid this issue, the developer can use the preprocessor directives:

In the source code:

#ifdef Q_WS_MAEMO_5
   //specific hildon/maemo5 code here

In the project file:

maemo5 {
   message("Hello Hildon")
   SOURCE += hildon.cpp
   HEADER += hildon.h
   FORMS   += hildon.ui

Home widget interaction

Main article: Qt4 and Hildon home widget interaction

Debugging a Qt application

Main article: Documentation/Maemo_5_Developer_Guide/Kernel_and_Debugging_Guide/Maemo_Debugging_Guide

Note: Fremantle Gdb 6.8 crashes in x86 and gives messed up backtraces on the device. Using gdb 7.0 is recommended. You can get gdb 7.0 sources from http://ftp.de.debian.org/debian/pool/main/g/gdb/gdb_7.0.orig.tar.gz, compile it (./configure && make) inside X86 and armel scratchbox targets. Here you can find GDB7 for fremantle x86 and armel.

/usr/local/bin/gdb7 ./myapp

Profiling a Qt application


Main article: Documentation/devtools/maemo5/oprofile


Main article: Documentation/devtools/maemo5/valgrind

Packaging a Qt application for Maemo

Main article: Packaging a Qt application

Maemo Qt API Reference

Maemo Qt is based on Qt for X11. It shares same APIs avoiding API breaks. In this way every Qt application that runs in other platforms (Windows, Mac OS X, Linux, S60, etc.) can run in Maemo devices as well. To Develop a Qt application you can use the Official Qt 4.6 for Maemo API documentation and the list below to see what are the Maemo changes.

Here are examples that show several maemo5 Qt widgets in Qt 4.6.

Maemo5 Readme file

There is a README file in Qt 4.6 source tree.

Contributing to the Maemo Qt Project

Maemo Qt is a community project. Contributing to the forum, sending us patches, give us feedbacks, tracking bugs are all activities that help us to improve the quality of our work.

Here there is a list of things that every person interested in helping us should read.

Stay updated

Any Maemo Qt developer should be updated and should participate to the discussions, for that he must join the Mailing list. BTW the mailing list is not for Maemo Qt Developers but it's open to Maemo Qt application developers too.

Introduction to Git

If you are a git newbie you maybe find interesting these links:

Understanding the structure of our Git repository

Main article: Qt Maemo Git Process


Make sure each scratchbox target has

 fakeroot apt-get build-dep libqt4-gui

(you may need to apt-get install libgl-dev too as it's not in the Build-Depends: yet)

Building Qt from Git repository

  1. Clone the repository:
    git clone git://gitorious.org/+qt-developers/qt/x11-maemo.git qt-maemo

  2. Change dir:
    cd qt-maemo
  3. Configure Qt:
    ./configure -maemo5
  4. Build Qt:
  5. Install Qt:
    make install

Merging branches changes in the mainline [OLD]

Before to merge your changes in the mainline, the code must be full working, cleaned and tested. A review from another developer is also needed in order to reduce the possibility to add errors.


QML is a GUI interface building scripting language for Qt. Check out the QML calculator example.


I'm trying to compile a Qt application for ARMEL, but I got the error below. What's wrong?
/targets/FREMANTLE_X86/usr/include/qt4/QtCore/qatomic_i386.h:127: error: impossible constraint in 'asm'
You are using x86 include files, then you have to update your Makefile. Running qmake before make will be solve this issue.
I'm trying to compile a Qt packcage for x86, but I got the error below. What's wrong?
In file included from maemo/gconfsymbols.cpp:41:
maemo/gconfsymbols_p.h:49:25: gconf/gconf.h: No such file or directory
Your scratchbox does not have /bin/sh, so when calling pkg-config from qmake, CFLAGS and LIBS are not set correctly. Running ln -s /scratchbox/tools/bin/sh /bin/sh will be solve this issue.
I installed Qt (libqt4-dev) to scratchbox and tried to build a sample application, but I got the error because some header files such as qhildonstyle.h, and qvfbhdr.h etc. were missing
libqt4-dev should copy all header files, but now, at least in 4.5.2-1maemo1, some files are missing. Please download file below and extract to your scratchbox system.