Creating a Mobile Application with Nokia Qt SDK
Note: To complete this tutorial, you must install Nokia Qt SDK. The installation program installs and configures the necessary tool chains for mobile application development.
This tutorial describes how to use Qt Creator to create a small Qt application, Battery Indicator, that uses the System Information Mobility API to fetch battery information from the device.
Creating the Battery Indicator Project
Note: Create the project with the Help mode active so that you can follow these instructions while you work.
- Select File > New File or Project > Qt Application Project > Mobile Qt Application > Choose.
The Introduction and Project Location dialog opens.
- In the Name field, type BatteryIndicator.
- In the Create in field, enter the path for the project files. For example, C:\Qt\examples, and then click Next.
The Select Required Qt Versions dialog opens.
- Select Maemo, Qt Simulator, and Symbian Device targets, and click Next.
Note: Targets are listed if you installed the appropriate development environment, for example, as part of the Nokia Qt SDK.
The Class Information dialog opens.
- In the Class Name field, type BatteryIndicator as the class name.
- In the Base Class list, select QDialog as the base class type.
Note: The Header File, Source File and Form File fields are automatically updated to match the name of the class.
- Click Next.
The Project Management dialog opens.
- Review the project settings, and click Finish to create the project.
The BatteryIndicator project now contains the following files:
The files come with the necessary boiler plate code that you must modify, as described in the following sections. You do not need to change the main.cpp file.
Declaring the Qt Mobility API
The New wizard automatically adds information to the .pro file that you need when you use the Qt Mobility APIs or develop applications for Symbian devices. You must modify the information to declare the Qt Mobility APIs that you use.
This example uses the System Info API, so you must declare it, as illustrated by the following code snippet:
CONFIG += mobility
MOBILITY = systeminfo
Each Mobility API has its corresponding value that you have to add as a value of MOBILITY to use the API. For a list of the APIs and the corresponding values that you can assign to MOBILITY, see the Quickstart Example.
The following code snippet shows information that is needed for applications developed for Symbian device. Qt Creator generated the UID for testing the application on a device. You only need to change the UID and capabilities if you deliver the application for public use and need to have it Symbian Signed.
TARGET.UID3 = 0xecbd72d7
# TARGET.CAPABILITY +=
TARGET.EPOCSTACKSIZE = 0x14000
TARGET.EPOCHEAPSIZE = 0x020000 0x800000
Designing the User Interface
- In the Editor mode, double-click the batteryindicator.ui file in the Projects view to launch the integrated Qt Designer.
- Drag and drop a Progress Bar (QProgressBar) widget to the form.
- In the Properties pane, change the objectName to batteryLevelBar.
Completing the Header File
The batteryindicator.h file contains some of the necessary #includes, a constructor, a destructor, and the Ui object. You must include the System Info header file, add a shortcut to the mobility name space, and add a private function to update the battery level value in the indicator when the battery power level changes.
- In the Projects view, double-click the batteryindicator.h file to open it for editing.
- Include the System Info header file, as illustrated by the following code snippet:
- Add a shortcut to the mobility name space, as illustrated by the following code snippet:
- Declare a private function in the private section, after the Ui::BatteryIndicator function, as illustrated by the following code snippet:
Completing the Source File
Now that the header file is complete, move on to the source file, batteryindicator.cpp.
- In the Projects view, double-click the batteryindicator.cpp file to open it for editing.
- Create a QSystemDeviceInfo object and set its value. Then connect the signal that indicates that battery level changed to the setValue slot of the progress bar. This is illustrated by the following code snippet:
deviceInfo = new QSystemDeviceInfo(this);
- Use the constructor to set initial values and make sure that the created object is in a defined state, as illustrated by the following code snippet:
BatteryIndicator::BatteryIndicator(QWidget *parent) :
Compiling and Running Your Program
Now that you have all the necessary code, select Qt Simulator as the target and click the button to build your program and run it in the Qt Simulator.
In Qt Simulator, run the runOutOfBattery.qs example script to see the value change in the Battery Indicator application. Select Scripting > examples > runOutOfBattery.qs > Run.
Testing on a Symbian Device
You also need to test the application on real devices. Before you can start testing on Symbian devices, you must connect them to the development PC by using an USB cable and install the necessary software on them.
- Install Qt 4.6.2 libraries, the Qt mobile libraries, and the TRK debugging application on the device. For more information, see Setting Up Development Environment for Symbian.
- Start TRK on the device.
- Click the Target Selector and select Symbian Device.
- Click Run to build the application for the Symbian device.
Testing on the Maemo Emulator
The Maemo emulator emulates the Nokia N900 device environment. You can test applications in conditions practically identical to running the application on a Nokia N900 device with the software update release 1.2 (V10.2010.19-1).
For more information, see Using the Maemo Emulator.