Qtopia Home - Classes - Hierachy - Annotated - Functions - Qt Embedded |

# Compile and Run SDK Example Application

- Developing for Qtopia
- The Qtopia SDK
  - The Example Application
  - Building Your Own Applications

## Developing for Qtopia

Qtopia is a windowing system for handheld devices. It offers developers the powerful Qt API, and provides users with fast and intuitive interaction.

Since Qtopia offers the complete Qt API, you can do much of your development on any of the other platforms for which Qt is available: Windows, Unix/X11, or Mac OS X. However, for optimal tailoring of your application to the smaller screen and other limitations of a small device, we recommend that you use the Qtopia SDK.

## The Qtopia SDK

The Qtopia SDK allows you to develop Qtopia applications under the Linux desktop environment using the Qt Virtual Framebuffer, which completely emulates the handheld Qtopia environment. It also includes cross-compiler software so that you can compile your application to run on the target device. If you do not already have the Qtopia SDK (this document is normally part of the SDK), contact info@trolltech.com, or see the Trolltech web site.

To build applications for the SHARP SL5000 or similar StrongARM-based devices, you will also need a StrongARM cross compiler.

### The Example Application

The SDK includes an example application. We recommend that you compile and run this example to learn how things work, before tackling your own projects.

Here are the steps necessary to compile and run the example program on the Linux desktop:

1. Check that the environment is correct: For the Qtopia SDK use

          export QPEDIR=/opt/Qtopia
          export QTDIR=$QPEDIR
          export DQTDIR=$QPEDIR
          export PATH=$QPEDIR/bin:$PATH
          export QMAKESPEC=qws/linux-generic-g++
          export LD_LIBRARY_PATH=$QPEDIR/lib:$LD_LIBRARY_PATH

2. Make a copy of the example:

          cd somewhere
          cp -r $QPEDIR/examples/application .
          chmod +w application/*
          cd application

3. Generate a Makefile:

          qmake -o Makefile application.pro

4. Build the example:

          make

5. Install the example (requires root privelges):

          su # root privileges required to install
          make install INSTALL_ROOT=$QPEDIR
          exit # no need to be root anymore

6. To run the example, first run the Qt Virtual Framebuffer:

          qvfb &

7. Then run the Qtopia environment:

          qpe

   Your application should now be available in the Applications tab which is visible inside the Qt Virtual Framebuffer window.

8. If you want to distribute your applications to others, build an RPM package. For example:

          mkipks -rpm -arch i386 example.control

9. To uninstall the example (requires root privelges):

          su # root privileges required to install
          make uninstall INSTALL_ROOT=$QPEDIR
          exit # no need to be root anymore

To make your own application, use the example program as a model. Make sure that when you add files to your project, you also add them to your project file (i.e. to `application.pro`) and rerun the `qmake` command to update the `Makefile` whenever you update the `.pro` file. This is not always required as qmake will rebuild the Makefile when the .pro file has changed.

To build you application for the SHARP SL5000 rather than just running on the desktop, the process is similar. The example below assumes you have installed the cross compiler in /usr/local/arm.

1. Check the environment is correctly set for the SHARP SL5000: For the Qtopia SDK use

          export QPEDIR=/opt/Qtopia/arm
          export QTDIR=$QPEDIR
          export DQTDIR=/opt/Qtopia
          export QMAKESPEC=qws/linux-sharp-g++
          export PATH=$QPEDIR/bin:/usr/local/arm/bin:$PATH

   replace /usr/local/arm/bin with the location of your ARM cross compiler.

2. Rebuild the makefile (`$QMAKESPEC` has changed) above:

          make clean
          qmake -o Makefile application.pro

3. Build it:

          make

4. Install it (note that this is now going into the `/opt/Qtopia/arm/` directory):

          su # root privileges required to install
          make install INSTALL_ROOT=$QPEDIR
          exit # no need to be root anymore

5. To install it on a device, build an `ipk` package file:

          su -m # root privileges required to strip the executable
          make packages
          exit # no need to be root anymore

The resulting `$QPEDIR/ipkg/example-1.0.0.ipk` can be installed on the SL5000 using Qtopia Desktop.

### Building Your Own Applications

Once you have built the example, you can proceed with writing your own applicatons. If you are not familiar with Qt, you should consult the Qt documentation when you have installed the SDK, or use the online Trolltech Documentation Site. The Qt Whitepaper provides a good overview of, and introduction to, the Qt API.

When you add more files to your application, just edit the project file (e.g. `application.pro`) and rerun `qmake`.

If you add conditional directives to your .pro file (eg. QTOPIA_PHONE for phone specific files) you should ensure that the TRANSLATABLES variable contains sources from ALL builds. This is so that you will have one set of translations to maintain for all your "editions". It is easiest if you create globally scoped variables to contain all the files. Like this:

    SOURCES=main.cpp
    HEADERS=main.h
    PHONE_SOURCES=main_ph.cpp
    PHONE_HEADERS=main_ph.h
    QTOPIA_PHONE {
        SOURCES+=$$PHONE_SOURCES
        HEADERS+=$$PHONE_HEADERS
    }
    TRANSLATABLES+=$$PHONE_SOURCES $$PHONE_HEADERS # Add this now so we don't forget later

    ...

    TRANSLATABLES*=$$HEADERS $$SOURCES # The * avoids duplicates

The `.ui` files are Qt Designer user interface files. You can create and edit these using Qt Designer:

       designer example.ui

Qt Designer's online documentation (accessible from the links mentioned above) includes a complete tutorial.