Qt4 Hildon Legacy

(Debugging a Qt application)
(Profiling a Qt application)
Line 142: Line 142:
[http://repository.maemo.org/pool/diablo/free/g/gdb/ gdb debian package for Diablo]
[http://repository.maemo.org/pool/diablo/free/g/gdb/ gdb debian package for Diablo]
-
== Profiling a Qt application ==
+
== [[Image:chart.png]] Profiling a Qt application ==
=== OProfile ===
=== OProfile ===
Oprofile is a low overhead system-wide profiler for linux. It can be used to find CPU usage bottlenecks in the whole system and within processes. It works fine in the device, but viewing the reports can take quite a long time (10 minutes) when fired up on N800/N810 devices. Therefore, it often makes sense to run opreport in scratchbox.
Oprofile is a low overhead system-wide profiler for linux. It can be used to find CPU usage bottlenecks in the whole system and within processes. It works fine in the device, but viewing the reports can take quite a long time (10 minutes) when fired up on N800/N810 devices. Therefore, it often makes sense to run opreport in scratchbox.

Revision as of 01:09, 28 February 2009

File:MaemoQtPicture.png

Contents

File:Intro.png Intro

What is Maemo?

Few words about the Maemo software platform

What is Hildon?

Hildon is an application framework for Linux operating system mobile devices (PDAs, mobile phones, etc), developed by Nokia for Maemo and now a part of GNOME, that focuses on providing a finger friendly interface

Read more

Developing in Maemo

Developer overview

Maemo SDK

If you want to get more info about the Maemo SDK or simply you want to install it on your linux box this is the page that you want to check: SDK Releases.

If you are not a Linux user and you want to develop for Maemo you can use a Maemo SDK Virtual Images.

What is Scratchbox?

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.

Read more...


File:Rocket.png Getting started

Installing the Maemo Scratchbox

If you want to install the maemo SDK on your linux box this is the page that you want to check: SDK Releases

Installing the Qt packages in Scratchbox

After Scratchbox and SDK are installed and working, you need to login, add the "extra" and "extra devel" repositories to your apt-get sources and install the Qt libs. Here's how:

  • Paste this into your Scratchbox shell (without the ">" prompt):
> echo "# Maemo extras and extras-devel
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" >> /etc/apt/sources.list
  • Run these commands:
> apt-get update
> fakeroot apt-get install libqt4-core
> fakeroot apt-get install libqt4-gui
> fakeroot apt-get install libqt4-dev
  • Do these steps for the DIABLO_X86 and the DIABLO_ARMEL target if you plan to build on both




File:Hammer.png Porting a Qt application in Maemo

Intro

Porting a Qt Desktop application to Maemo requires very few efforts; This because the Maemo Qt libraries will take care of giving the Hildon Maemo look & Feel and enabling the hildon input method for your application.

How to compile a Qt application in scratchbox

All the Qt tools that you need are available in scratchbox. So in order to compile a Qt application you need to follow the standard Qt way:

qmake -project
qmake file.pro
make

Overriding the Qt maemo changes

Maemo Style

The Maemo style is the default style of the Qt applications that run in Maemo. The other styles available in Qt 4.4 maemo are QCleanLooks, Windows and Plastique (It will be available in the next packages of Qt).

You can force your application to use another style in several way:

1. Running your application with the flag -style <style_name>

$> ./qt-test-application -style windows

HINT: You can put this flag in the Exec field of the desktop file that launch the application.

2. If you want to change your code, you can use this static function:QApplication::setStyle( QStyle * style )

3. If you want to change the style only for a particular widget, you can call this function in the widget constructor: QWidget::setStyle( QStyle * style )

Showing the status bar

The hildon applications don't have a stuatus bar. Qt for maemo hide the status bar by default. You can show it again modifying your code. TODO

Adding Maemo changes to a Qt Application

Some methods of Qt for Maemo are not available in the "standard" Qt libs. Then 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, for example:

#ifdef Q_WS_HILDON
   //Specific hildon code here 
#endif

Limitations

TODO

File:Bug.png Debugging a Qt application

GDB

Intro

The Gnu Project Debugger, or gdb for short, is a general purpose debugger that can be used for various debugging purposes.

Debugging a Qt application into scratchbox

TODO

Debugging a Qt application into the device

1. Installing gdb into the device

A. add the sdk tools repository to the catalogue list
B. install gdb by using apt-get (require around 6 Mb of space)

2. Install the debug symbols files in scratchbox (ARMEL target)

apt-get install libqt4-dbg

3. Run the application (device side)

$gdbserver 0.0.0.0:1234 ./qtApplication

4. Run the gdb client on your host PC (scratchbox side)

[sbox-DIABLO_ARMEL: ~/TEST/svn/qt4-x11-4.4.0/examples/widgets/tablet] > gdb ./qtApplication

5. Set the target of gdb

(gdb) target remote 172.21.37.117:1234

6. Tell to gdb to continue to debug the application on the device

(gdb) continue

7. Wait some moments...

8. Your application will appear on the device screen.

9. Happy debugging!

Links

GDB documentation & Tutorials

GDBServer man page

maemo debugging guide

gdb debian package for Diablo

File:Chart.png Profiling a Qt application

OProfile

Oprofile is a low overhead system-wide profiler for linux. It can be used to find CPU usage bottlenecks in the whole system and within processes. It works fine in the device, but viewing the reports can take quite a long time (10 minutes) when fired up on N800/N810 devices. Therefore, it often makes sense to run opreport in scratchbox.

If you want to know more about OProfile in Maemo click here to read a good how to.

Packaging a Qt application for Maemo

Find out more..

Extended API

There are no API breaks in Maemo Qt. You can collect the info that you need to develop in Maemo with Qt checking the Official Qt 4.4 API Documentation and the list below.

 Double click radius
 The application can set the double click radius by using:
 static void QApplication::setDoubleClickRadius(int);
 static int QApplication::doubleClickRadius();
 The default value is 20px, usually you don't need to change it.
 QTableEvents are able to get the pressure value from the touchscreen.
  - The eventdeviceType is for the touchscreen is set to QTabletEvent::Stylus.
   
 Finger poke is emulated in scratchbox by the Middle Mouse button (NOTE: There is no Fullscreen VKB in scratchbox)

 QInputEvents don't move the cursor. 
 It's mandatory to get working the HIM moving the cursor via QInputMethodEvents.
 Why is it mandatory?  
 Because if the user select text with the finger from the right to the left, we are able to remove the highlighted text, but the
 cursor will be moved on the last char instead to stay on the first one.
  
 To do that some changes has been added to some widget function like: widget::inputMethodEvent(QInputMethodEvent *e).
 Modifing that function in some custom widgets may be necessary.
 Don't reimplementing that function will break some fullscreen virtual keyboard features.
 
 Hardcoded Keys:
 In the QMainWindow:
 - F6 - Toggle fullscreen the application
 - F4 - Shows/Hides the application context menu
 - Zoom in  - is a standard key sequence QKeySequence::ZoomIn
 - Zoom out - is a standard key sequence QKeySequence::ZoomOut
 Input Method:
 Maemo Qt uses the Hildon IM as default Input method.
 Each kind of widget can set the IM mode. This allows the input method to focus on the type of input that the application is expecting.
 Eg: spinboxes can receive only numeric characters (1-9).
 
 NOTE: Qt widgets like QTextEdit, QLineEdit... set the right input method mode automatically. 
 
 A developer can change it by using:
   void QInputContext::setInputMode(int mode);
 It will update immediately the Hildon Input method to use the selected IM mode.  
 
 HIC Modes:
   HILDON_GTK_INPUT_MODE_ALPHA 	alphabetical characters and whitespace
   HILDON_GTK_INPUT_MODE_NUMERIC 	numbers 0-9 and the '-' character
   HILDON_GTK_INPUT_MODE_SPECIAL 	special characters
   HILDON_GTK_INPUT_MODE_HEXA 	hexadecimal characters; numbers 0-9, characters a-f, and A-F
   HILDON_GTK_INPUT_MODE_TELE 	telephone numbers; numbers 0-9, whitespace, and the characters "pwPW/().-+*#?,"
   HILDON_GTK_INPUT_MODE_FULL 	unrestricted entry mode, combination of the alpha, numeric and special modes.
   HILDON_GTK_INPUT_MODE_MULTILINE 	the client contains multiple lines of text or accepts linebreaks in the input.
   HILDON_GTK_INPUT_MODE_INVISIBLE 	do not echo or save the input in the IM when entering sensitive information such as passwords.
   HILDON_GTK_INPUT_MODE_AUTOCAP 	automatically capitalize the first letter at the start of a sentence.
   HILDON_GTK_INPUT_MODE_DICTIONARY 	enable predictive dictionaries and learning based on the input.
  
 Example:
   For a password field we need to set a specific IM mode:
   int mode = HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE
   QInputContext qic = widget->inputContext();
   qic->setInputMode(mode);
 
 If you are developing a Custom widget able to receive input text, you can instruct your widget to use the right IM Mode just returning
 the mode.
 
 - How does it work?
 The Hildon IM sends a XMessage to pop up the "Virtual Keyboard" (or better the Main HIM UI) when an input widget receive the focus.
 The IM before to raise the VKB, makes an inputMethodQuery to the widget retrieving the IM mode.
 If the developer of the custom widget doesn't set the mode property, the IM will use HILDON_GTK_INPUT_MODE_FULL (the default mode) for that widget.
 
 Setting the ImMode is quite easy. Check the code below for more understanding.
  
 QVariant QAbstractSpinBox::inputMethodQuery(Qt::InputMethodQuery query) const
 {    
   Q_D(const QAbstractSpinBox);
   switch(query) {
       case Qt::ImMode:{
           int mode = HILDON_GTK_INPUT_MODE_NUMERIC;
           return QVariant(mode);
       }
       default:
           return d->edit->inputMethodQuery(query);
   }
 }