Building apps for the Ubuntu Phone

Slashdot it! Delicious Share on Facebook Tweet! Digg!
© Canonical

© Canonical

Mobile Assignment

The QML Toolkit lets you create apps for the new Ubuntu smartphone system. We'll help you get started with setting up the QML development environment.

The news that Canonical is working on a version of Ubuntu for the smartphone drew excitement from industry-watchers around the world. However, if you've actually downloaded the trial version onto your own smartphone, you might have hit a wall: all is not tried and tested.

The good news is that, although the actual Ubuntu phone OS is still in incubation, the QML Toolkit, which is used to build apps for the new system, is available for users who want to experiment with developing for the Ubuntu Phone. This article shows how to get started with the QML Toolkit development environment. The instructions are largely based on the work of Canonical developer David Planella, who is responsible for efforts around the new Ubuntu phone apps and has a website [1] dedicated to encouraging QML development (see the box titled "What is QML").

What is QML?

QML, which stands for the Qt Modeling Language, is a part of Qt Quick, a development toolkit used to create graphical interfaces for the Qt Framework. As a scripting language, QML integrates JavaScript into the C++-based Qt5 framework and is primarily used for developing graphical interfaces for mobile apps. The Qt Declarative runtime environment interprets the code written in QML.

This article describes how you can use Qt Creator to set up a development environment for QML. I won't delve into the code itself. (You'll find several good online tutorials on QML coding.) The prerequisite is that you use at least Ubuntu 12.10, because the components for "Quantal Quetzal" are required. (Some developers have reported success with installing the Quantal packages on Ubuntu 12.04 [2], but I have not tested this alternative.

Ubuntu 12.10 is the first version to include QML support, and the steps for setting up QML have gotten easier with Ubuntu 13.04. As with many new technologies, the configuration steps are a "moving target" as tools and procedures evolve.

Hands on: Qt 5 (12.10)

If you are running Ubuntu 13.04, all you have to do to get started is install the ubuntu-sdk package.

If you are running Ubuntu 12.10, the first thing you need is a very recent version of Qt5 that you can get from a PPA. Use the following commands:

$ sudo add-apt-repository ppa:canonical-qt5-edgers/qt5-beta1
$ sudo apt-get update
$ sudo apt-get install qt5-meta-full

You get the essential Qt packages onto your machine by installing the qt5-meta-full package. Look for the executable Qt applications in the /opt/qt5/bin directory. To run the executables system-wide on Ubuntu, you'll need to use Bash. To do this, open a terminal using Ctrl+Alt+T and enter the following command:

$ echo 'export PATH=/opt/qt5/bin:$PATH' >> ~/.bashrc

The path now ends in the hidden configuration file ~/.bashrc .

The qt-components are reusable QML files or components for Qt Quick – certain buttons and other graphical elements. These components are especially for Ubuntu, and you'll install them with the following steps (from the PPA):

$ sudo add-apt-repository ppa:ui-toolkit/ppa
$ sudo apt-get update
$ sudo apt-get install qt-components-ubuntu*notepad-qml qtcreator

As you might have noticed, Qt Creator is immediately installed at this point. The graphical application helps in developing GUIs with Qt and is also ideal for building the desired QML interfaces. But, you first need to link the Integrated Development Environment (IDE) with qmlscene to invoke the code directly from Qt Creator. qmlscene is a viewer for QML documents.

Preparing Qt Creator

You don't need to install qmlscene separately, because it's already in the /opt/qt5/bin directory with the Qt5 version. Start Qt Creator with Bash or from the HUD and, if you are running Qt Creator on Ubuntu 12.10, choose Tools | Options . On the External Tools tab, select Preview (qmlviewer) . Double-clicking changes the option to Preview (qmlscene) and shows up later as a menu item in Qt Creator. Next to Executable Files , click the Select button and navigate to the /opt/qt5/bin directory, in which you choose qmlscene . Clicking Open and OK completes the task. (Again these configuration steps are not necessary if you have installed the ubuntu-sdk package on 13.04.)

You can now create your first project, which you open using Files | New File or Project . Under Projects , select Applications and, right next to it, choose Qt Quick UI (Qt Quick 2 UI on 13.04).

Next, give the project a suitable name. In his tutorial, David Planella describes how you can develop a currency conversion app with the name CurrencyConverter.

You will need to have write permission for the application folder. You can place the folder in your home directory, for example, in /home/{USERNAME}/qml . Optionally, you could use a version control program such as Bazaar to protect the code [3].

Buy this article as PDF

Express-Checkout as PDF

Pages: 3

Price $0.99
(incl. VAT)

Buy Ubuntu User

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content