PyQt4 on the Qtopia Greenphone
Creating widgets interactively on the phone over a telnet connection.
Overview
Both Python and PyQt are viable choices for software development on Embedded Linux platforms that use Qt as their underlying GUI framework. In particular, devices such as the Greenphone are easily capable of running PyQt applications with streamlined user interfaces that have been adapted or specially written for small screen sizes.
This document describes the process used to compile all the necessary libraries needed by PyQt applications for the Greenphone. With some adjustment, the steps described here may work for other embedded environments.
The main problems with getting a PyQt development environment working on the Greenphone are due to difficulties with cross-compilation and the issue of matching the configuration of PyQt to the Qt build on the device.
Although SIP can be cross-compiled relatively easily, the Python build system doesn't support cross-compilation by default, and PyQt requires some patching in order to allow cross-compilation. In addition, PyQt needs to be modified to introduce configurable features that correspond to those in Qtopia Core.
Setting up a cross-compiler
The first thing we need to do is to obtain a cross-compiler that can generate appropriate libraries and executables for the Greenphone. We do this by building a crosstool toolchain for the same combination of gcc and glibc that were used to build the Qtopia Phone Edition software already on the device.
- Download a crosstool package and unpack it.
For Qtopia Phone Edition 4.3 builds, we need to build a toolchain based on GCC 4.1.1 and glibc 2.3.6. The files that are used to describe this configuration can be found in the Qtopia Phone Edition package (for example, the Open Source package found on the Qtopia Downloads page).
Unpack the package and look in the devices/greenphone/rootfs/toolchain directory.
- Copy the contents of that directory into your unpacked crosstool directory.
The trolltech-greenphone.sh script that is used to start the build process for the cross-compiler contains some environment variable definitions that need to be customised for your system.
Set the TARBALLS_DIR variable to refer to the directory that crosstool will use to place files it obtains from the Internet.
Set the RESULT_TOP variable to refer to the directory in which the result will be placed. (If all goes well with the build process, this directory will contain a directory called gcc-4.1.1-glibc-2.3.6.)
If you're using tools to parallelize compilation, you may want to disable them now if you think they will interfere with the build process.
Execute trolltech-greenphone.sh from within the unpacked crosstool directory. (This will take some time, since the build process involves downloading and compiling the sources to the Linux kernel, GCC, glibc and binutils.
Hopefully, this should all work as expected.
Configuring the build
The Building_Qtopia_Core_and_PyQt4.txt file contains a recipe for configuring and building Python, SIP, Qtopia Core and PyQt4 for the Greenphone. Create a new directory and copy this file into it.
The file contains some paths that need to be updated specifically for your system. These are described in the following list:
TARGET_TOOLS should refer to the bin directory containing the compilers built by crosstool; e.g., /home/dboddie/Software/Greenphone/gcc-4.1.1-glibc-2.3.6/arm-linux/bin
NATIVE_TOOLS should refer to the directory in which you want native versions (for your desktop machine) of Python and SIP to be installed. You may already have native versions of these installed on your desktop machine, but these versions will be specially configured and patched later on.
TARGETDIR and ROMDIR should refer to the root directory beneath which the final cross-compiled binaries will be installed. This typically reflects the structure of the file system on the Greenphone. For example, if PyQt is to be installed on a Flash memory device, both these variables should refer to the /mnt/sd/Qtopia directory.
You should also update any existing instances of /mnt/sd/Qtopia you find in the file if you change the values of TARGETDIR and ROMDIR from their defaults.
You may need to create the directories referred to by TARGETDIR and ROMDIR if they do not already exist. Be careful! The default value may refer to an existing file system on your desktop machine.
Building the native tools
Locate the archives referred to in the first section of the recipe and copy them into the build directory you created in the previous section. The archives containing patches and changes can be found on this site.
- At the command line, enter the build directory and execute all the commands in the first section. You should now have a directory containing unpacked versions of all the components needed to build the tools.
- Execute the commands in the next two sections to build and install native versions of Python and SIP.
If all went well, you should now be able to configure and build Python for the Greenphone.
PyQt Wiki