MeeGo 1.2 Harmattan Developer Documentation Develop for the Nokia N9

Integrating Qt Creator with Scratchbox in Linux environment

Qt Creator is a cross-platform C++ integrated development environment that includes a visual debugger and an integrated GUI layout and forms designer. The editor's features include syntax highlighting and autocompletion, among others.

When you have added support for Scratchbox toolchain in Qt Creator:

  • You can develop complex applications that use Linux build tools.
  • You can run applications under simulated ARM or x86 environment with full MeeGo 1.2 Harmattan library and style support.

This section describes how to set up the Scratchbox target for Qt Creator and how to compile and run an application under Scratchbox from Qt Creator in Linux (Ubuntu) environment.

To use Qt Creator with Scratchbox in Linux environment, you must do the following:

  1. Install Qt, Qt Creator, and Scratchbox.
  2. Set up the host environment.
  3. Create a Scratchbox Qt version in Qt Creator.

Installing Qt, Qt Creator and Scratchbox

1. To install Qt in the host workstation, enter the following command:

apt-get install libqt4-dev

2. To set up and use Scratchbox, see Installing Harmattan Platform SDK.

3. To set up Qt Creator, follow the instructions given in Installing Qt Creator on Linux.

Setting up the host environment

When setting up the host environment, use a path that does not pre-exist and is not in the PATH environment variable by default. Otherwise the changes can have side effects even though you use generic file names, such as qmake and make. For example, the path /usr/local/bin/sbox used in this section is recommended.

Prerequisite:

  • You have selected HARMATTAN_X86 inside Scratchbox.

1. To ensure that working directories under host and Scratchbox are the same, create a symlink to the working directory under Scratchbox home to host systems home directory. Enter the following commands:

cd
mkdir /scratchbox/users/$USER/home/$USER/scratchbox
ln -s /scratchbox/users/$USER/home/$USER/scratchbox scratchbox

You now have the following directory structure inside Scratchbox and in the host:

~/scratchbox

Note: You must use this shared folder when developing your projects.

2. To compile, create two shell scripts /usr/local/bin/sbox/qmake and /usr/local/bin/sbox/make on your Linux host, with the following content:

/usr/local/bin/sbox/qmake:

 #!/bin/bash
 SBOX_TARGET="HARMATTAN_X86"
 SBOX_USER="tester"
 /usr/bin/scratchbox -d `pwd` qmake $@ | sed "s/:\//:\/scratchbox\/users\/$SBOX_USER\/targets\/$SBOX_TARGET\//g"

Remember to change the SBOX_USER and SBOX_TARGET to match the user name and target name inside the Scratchbox. The qmake script forwards the qmake request from Qt Creator to Scratchbox. The script also adds the correct paths for the ABI detection of the Qt Creator to the qmake request.

/usr/local/bin/sbox/make:

#!/bin/bash
/usr/bin/scratchbox -d `pwd` make $@

3. To run your application from Scratchbox using Qt Creator, you need one more script in /usr/local/bin/sbox directory of your host.

Because Qt Creator expands symbolic links, /home/$USER/scratchbox becomes /scratchbox/users/$USER/home/$USER. Thus, you must remove the prefix to ensure that the scratchbox meego-run script works correctly. To remove the prefix, enter the following contents in the /usr/local/bin/sbox/run script:

#!/bin/sh
/usr/bin/scratchbox -d `echo $PWD| sed -e "s_/scratchbox/users/[A-Za-z0-9]*/_/_"` meego-run $@

After you have created the script, add execution rights for it. Enter the following command:

sudo chmod +x /usr/local/bin/sbox/run

4. To make the scripts executable, enter the following shell command:

chmod +x /usr/local/bin/sbox/make /usr/local/bin/sbox/qmake /usr/local/bin/sbox/run

Creating Scratchbox Qt version under Qt Creator

In Qt Creator, create a new project or select an existing one that uses at least the desktop target. Harmattan and Qt Simulator targets do not allow you to choose a custom Qt version.

Configuring Qt Creator

1. When you have the project open in Qt Creator, select Tools > Options and open the Qt4 tab.

2. Click Add and select the recently created /usr/local/bin/sbox/qmake script. Then enter a name for the new Qt version.

In this example, the name Qt 4.7.4 (sbox) is used.

If everything went right, Qt version 4.7.4 for Desktop is displayed in Qt Creator.

3. Click OK.

Configuring build settings for the current project

1. Switch to Projects mode button.

2. On the target toolbar, select Desktop > Build to configure the build settings.

3. Select the build configuration from Edit Build Configuration. In this example, the name Qt 4.7.4 (sbox) is used.

4. Make sure that the recently created Qt version appears in Qt Version.

5. Clear Shadow build check box to ensure better compatibility.

6. You need to set make to be overridden in Build Steps with the /usr/local/bin/sbox/make script. To do this, select Details from Make and browse for /usr/local/bin/sbox/make in the Override make field.

You now have a working build configuration for the current project.

Note: You must execute the above steps for each project that you compile with this setup.

Testing the new build settings

1. To test the setup, select Build > Rebuild Project: <your project name> from the top menu.

2. Select Edit to view the output.

3. Check that the project compiles as it did before and that the following lines appear in Compile Output:

The process "/usr/local/bin/sbox/qmake" exited normally.
The process "/usr/local/bin/sbox/make" exited normally.

Executing your application in Scratchbox using Qt Creator

Configuring run settings of the current project in Qt Creator

1. Switch to Projects mode button.

2. On the target toolbar, select Desktop > Run to configure the run settings.

3. Click Add next to Run configuration.

4. Select Custom executable from the pop-up menu.

5. In the Executable field, browse for the /usr/local/bin/sbox/run script.

6. In the Arguments field, add the binary name of your application (usually the project name by default).

Note: You need to use ./ in front of the application name.

File:linux-shot4-project-run-settings-run-settings-customexecutable-arguments.png

You have now successfully configured the run settings for the current project.

Executing the application in Scratchbox using Qt Creator

1. To start the framebuffer X server (Xephyr), enter the following command:

Xephyr :2 -host-cursor -screen 480x854x16 -dpi 96 -ac +extension Composite

2. Now that Xephyr is running, launch meego-sb-session on it. Enter the following commands:

/scratchbox/login
[sbox-HARMATTAN_X86: ~]> meego-sb-session start

3. To run your Qt application, click Run.

Your application appears in the Xephyr window.