Creating A Mobile Application With Nokia QT SDK
Creating A Mobile Application With Nokia QT SDK
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.
1. Select File > New File or Project > Qt Application Project > Mobile Qt
Application > Choose.
The Introduction and Project Location dialog opens.
2. In the Name field, type BatteryIndicator.
3. In the Create in field, enter the path for the project files. For example,
C:\Qt\examples, and then click Next.
Note: Targets are listed if you installed the appropriate development environment, for
example, as part of the Nokia Qt SDK.
Note: The Header File, Source File and Form File fields are automatically updated
to match the name of the class.
7. Click Next.
batteryindicator.h
batteryindicator.cpp
main.cpp
batteryindicator.ui
BatteryIndicator.pro
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.
symbian {
TARGET.UID3 = 0xecbd72d7
# TARGET.CAPABILITY +=
TARGET.EPOCSTACKSIZE = 0x14000
TARGET.EPOCHEAPSIZE = 0x020000 0x800000
}
#include <QSystemInfo>
3. Add a shortcut to the mobility name space, as illustrated by the following code
snippet:
QTM_USE_NAMESPACE
4. Declare a private function in the private section, after the Ui::BatteryIndicator
function, as illustrated by the following code snippet:
5. private:
6. Ui::BatteryIndicator *ui;
7. void setupGeneral();
8.
QSystemDeviceInfo *deviceInfo;
1. In the Projects view, double-click the batteryindicator.cpp file to open it for editing.
2. 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:
3. void BatteryIndicator::setupGeneral()
4. {
5. deviceInfo = new QSystemDeviceInfo(this);
6.
7. ui->batteryLevelBar->setValue(deviceInfo->batteryLevel());
8.
9. connect(deviceInfo, SIGNAL(batteryLevelChanged(int)),
10. ui->batteryLevelBar, SLOT(setValue(int)));
}
11. 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:
12. BatteryIndicator::BatteryIndicator(QWidget *parent) :
13. QDialog(parent),
14. ui(new Ui::BatteryIndicator),
15. deviceInfo(NULL)
16. {
17. ui->setupUi(this);
18. setupGeneral();
}
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.
1. 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.
2. Start TRK on the device.
3. Click the Target Selector and select Symbian Device.
4. Click Run to build the application for the Symbian device.