![]() |
Home · All Classes · All Functions · | ![]() |
Files:
The following steps outline how to make a simple "hello world" like application that uses Qt Mobility. It is assumed that Qt Mobility has been successfully built and environment variables have been set as per Installation Guide.
One can start using Qt Mobility with 3 simple steps.
Steps 1 and 2 are shown in the example below:
#include <QApplication> #include <QLabel> #ifdef Q_OS_SYMBIAN #include <qsysteminfo.h> #else #include <QSystemInfo> //(1) #endif QTM_USE_NAMESPACE //(2) int main(int argc, char *argv[]) { QApplication app(argc, argv); QSystemInfo s; QLabel *label = new QLabel(QObject::tr("hello ").append(s.currentCountryCode())); label->show(); label->resize(100,30); return app.exec(); }
This example uses the QSystemInfo headers to print out the system's current country code. All the domain APIs are wrapped within a Qt Mobility namespace and thus developers need to use the QTM_USE_NAMESPACE macro. (Note: If you are on the Symbian platform you will need to define the actual header file, in this case <qsysteminfo.h> rather than using the standard header form <QSystemInfo>, this is a known bug that is to be addressed in a future release)
In step 3, to specify that our project is using System Information we declare in the project file:
CONFIG += mobility MOBILITY += systeminfo
The project file states that the application uses Qt Mobility and that it requires the System Information API. By adding mobility to CONFIG qmake finds the mobility.prf file in $QTDIR/mkspecs/features and includes it when processing the current project file. mobility.prf is generated when running the QtMobility configure script and points qmake to the relevant include and prefix paths and ensures that deployment and package dependencies are set. The MOBILITY variable itself is part of mobility.prf and is used to determine the QtMobility library the current project should link to (in this example the SystemInfo library).
Each QtMobility API has its corresponding value which has to be added to MOBILITY. The subsequent table lists the APIs and the corresponding values that can be assigned to MOBILITY.
Domain | Value |
---|---|
Bearer Management | bearer |
Contacts | contacts |
Location | location |
Multimedia | multimedia |
Messaging | messaging |
Publish And Subscribe | publishsubscribe |
Service Framework | serviceframework |
System Information | systeminfo |
Versit | versit |
When developing on Symbian we will also need to add the required capabilites to the project file in order to satisfy the Symbian security model:
symbian { TARGET.CAPABILITIES = LocalServices ReadUserData WriteUserData NetworkServices UserEnvironment Location TrustedUI ReadDeviceData }
Domain | Symbian Capabilities |
---|---|
Bearer Management | ReadUserData NetworkServices (NetworkControl for QNetworkSession::stop()) |
Contacts | ReadUserData WriteUserData SwEvent ReadDeviceData WriteDeviceData |
Location | Location |
Multimedia | UserEnvironment ReadUserData WriteUserData ReadDeviceData WriteDeviceData |
Messaging | LocalServices ReadUserData WriteUserData NetworkServices UserEnvironment ReadDeviceData WriteDeviceData |
Publish And Subscribe | ReadDeviceData WriteDeviceData |
Service Framework | No capabilities requried by itself, the plugins may have capability requirements. |
System Information | LocalServices ReadUserData WriteUserData NetworkServices UserEnvironment Location TrustedUI ReadDeviceData |
And we're done. If you are using the command line simply enter:
qmake
make //or nmake on Windows
to generate the executable which can then be run.
If you are developing for Symbian, to make a debug build for the emulator run:
qmake make debug-winscw
This assumes that qmake is in your %PATH% and Qt has been built for the emulator already.
To make a release build and SIS package for a device run:
qmake make release-gcce make sis
For further details on how to build applications for Symbian see The Symbian Platform - Introduction to Qt and Qt Quick Start
Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies) | Trademarks | Qt Mobility Project 1.0.0 |