Creating Qt Applications for Symbian, Beta
Creating Qt
Applications for
Symbian
Lecture 3
Copyright ? 2010 Nokia Corporation.
1
License
Copyright ? 2010 Nokia Corporation and/or its subsidiary(-ies).
Nokia, the Nokia logo, Qt, and the Qt logo are trademarks of Nokia Corporation and/or its subsidiary(-ies) in Finland and other countries. Additional company and product names are the property of their respective owners and may be trademarks or registered trademarks of the individual companies and are respectfully acknowledged. For its Qt products, Nokia operates under a policy of continuous development. Therefore, we reserve the right to make changes and improvements to any of the products described herein without prior notice. No warranty, express or implied is made about the accuracy and/or quality of the information contained herein. Under no circumstances shall Nokia Corporation or any of its subsidiary(-ies) be responsible for any loss of date, or income, or any direct, special, incidental, consequential or indirect damages whatsoever.
This document is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 2.5 License.
For more information, see https://www.wendangku.net/doc/5f17001766.html,/licenses/by-nc-sa/2.5/legalcode for the full terms of the license.
Copyright ? 2010 Nokia Corporation.
2
Lecture Overview
?Qt Mobility APIs
?Exercise 8
?Summary
Copyright ? 2010 Nokia Corporation.
3
Creating Qt Applications for Symbian, Beta
Creating Qt
Applications for
Symbian
Qt Mobility APIs
Copyright ? 2010 Nokia Corporation.
4
Lecture Overview
?Qt Mobility APIs
?Exercise 8
?Summary
Copyright ? 2010 Nokia Corporation.
5
Qt Mobility APIs
?What is the Mobility Project?
?A project within Nokia that is creating a new suite of Qt APIs for mobile device functionality.
?What is the problem that these new APIs will solve?
?Developers looking to take advantage of mobile device functionality would
usually have to use APIs outside of Qt. These new APIs make Qt an even
more comprehensive application and UI framework.
?Developers will be able to write cross-platform Qt applications that take
advantage of mobile device functionality.
?Mobility APIs are of great interest and importance to Qt developers
targeting mobile devices
Copyright ? 2010 Nokia Corporation.
6
Installing Qt Mobility Libraries to the
Device
?You need to have Nokia PC Suite or Ovi Suite
?The Qt Mobility API installation package qtmobility.sis can be found in
path\to\NokiaQtSDK\Symbian\sis\qtmobility.sis
?Double-clicking qtmobility.sis opens an installation dialog
?Click yes and continue the installation on the device
Copyright ? 2010 Nokia Corporation.
7
Alternatively, the qtmobility.sis file can be downloaded with the Qt Mobility Package from:
https://www.wendangku.net/doc/5f17001766.html,/products/appdev/add-on-products/catalog/4/new-qt-apis/mobility
Bearer Management API
?Provides way to control which connection is used
?For example, the program can choose to use either 3G or WLAN in
different situations
?With this API, also a smooth switch from one bearer to another is possible QNetworkConfigurationManager manager;
const bool canStartIAP = (manager.capabilities() &
QNetworkConfigurationManager::BearerManagement);
QNetworkConfiguration cfg = manager.defaultConfiguration();
if (!cfg.isValid() || !canStartIAP)
return;
switch(cfg.type()) {
case QNetworkConfiguration::UserChoice: {
// automatic IAP resolution by system or by asking user as
// part of QNetworkSession::open() call
QNetworkSession *session = new QNetworkSession(cfg);
session->open(); break; }
...
}
Copyright ? 2010 Nokia Corporation.
8
Contacts API
?Provides way to
?Add, remove and update contacts and contact groups
?Search for contacts and contacts groups
// cm is a QContactManager object
QContact alice;
QContactName aliceName;
aliceName.setFirst(“Alice”);
aliceName.setLast(“Jones”);
alice.saveDetail(&aliceName);
/* Add a phone number */
QContactPhoneNumber number;
number.setContexts(QContactDetail::ContextHome);
number.setSubTypes(QContactPhoneNumber::SubTypeMobile);
number.setNumber(“12345678”);
alice.saveDetail(&number);
alice.setPreferredDetail(”DialAction”, number);
cm->saveContact(&alice);
Copyright ? 2010 Nokia Corporation.
9
Location API
?Provides easy way to access location information
?Location data can be fetched with the following ways
?one-time fetch
?periodically
?on position change
?QGeoAreaMonitor provides also a way to obtain notification when a specified region is entered or exited
QGeoPositionInfoSource *source =
QGeoPositionInfoSource::createDefaultSource();
if (source) {
connect(source, SIGNAL(positionUpdated(QGeoPositionInfo)),
this, SLOT(positionUpdated(QGeoPositionInfo)));
source->startUpdates();
}
// slot positionUpdated is now called each time the position is updated
Copyright ? 2010 Nokia Corporation.
10
Messaging API
?Provides way to send, reply and receive messages
?Including email, SMS and MMS messages
?Also a way to search messages is provided
?Search results can be filtered and ordered
QMessage message;
message.setType(QMessageAddress::Email);
QString recipient(“user@https://www.wendangku.net/doc/5f17001766.html,>”);
message.setTo(QMessageAddress(QMessageAddress::Email, recipient));
message.setSubject(“Example subject”);
message.setBody(“Example body text”);
QMessageService *m_service = new QMessageService();
if (!m_service->send(message))
QMessageBox::warning(0, tr(“Failed”), tr(“Unable to send message”));
Copyright ? 2010 Nokia Corporation.
11
Multimedia API
?Provides way to
?show pictures and play music, video files and multimedia stream ?record to record sound
?listen to the radio
QMediaPlayer *player = new QMediaPlayer;
...
player->setMedia(QUrl::fromLocalFile(”test.raw”));
player->setVolume(50);
player->play();
Copyright ? 2010 Nokia Corporation.
12
Publish and Subscribe API
?Provides way to publish items, read item values, navigate through and subscribe to change notifications.
?Data is stored as a tree-like data structure. When a child of a node is changed, also the node itself is changed. This allows applications to be notified always when any child is changed for some node.
?Values are fetched with a path string, for example,
?/Device/Network/Interfaces/eth0/Name
QString valueSpace = “/Device/Network/Interfaces/eth0/Name”;
QValueSpaceSubscriber *subscriber = new
QValueSpaceSubscriber(valueSpace);
QObject::connect(subscriber, SIGNAL(contentsChanged()),
this, SLOT(infoChanged()));
Copyright ? 2010 Nokia Corporation.
13
Service Frameworks API
?Provides a unified way of finding, implementing and accessing services
across multiple platforms.
?A service is an independent component that allows a client to perform a
well-defined operation.
?Similar to plugins, except that there is no need to know the interface
beforehand.
?For example, application could provide a service interface named
“com.nokia.qt.examples.fileStorage”, having a method “deleteFiles”.
?Other applications can invoke methods of the service provider using the
QServiceManager and QMetaObject's “invokeMethod” method.
QServiceManager manager;
...
QObject *fileStorage = manager.loadInterface(foundServices.at(0));
QMetaObject::invokeMethod(fileStorage, “deleteFiles”);
Copyright ? 2010 Nokia Corporation.
14
To use the interface object, you could also cast it dynamically with the qobject_cast.
For example,
QServiceManager manager;
QServiceFilter filter(”com.nokia.qt.examples.FileStorage”);
filter.setServiceName(”FileManager”);
QList
foundServices = manager.findInterfaces(filter);
QObject *object;
object = manager.loadInterface(foundServices.at(0));
MyFileStorage *fileStorage = qobject_cast
if (fileStorage != 0) {
fileStorage->deleteFiles();
}
The downside is that in this case you need to know the specific class of the returned object already when compiling.
System Information API
?Provides way to obtain information about the features and versions ?Versions of Operating system, firmware, WebKit, Qt
?Device information like battery level, screen size, SIM, input methods ?Display information
?Features such as GPS, bluetooth, wlan, camera, fm radio etc
// Battery level (range 1 - 100)
QSystemDeviceInfo di;
di.batteryLevel();
// returns Qt lib version
QSystemInfo systemInfo;
QString qtVersion = systemInfo.version(QSystemInfo::QtCore);
Copyright ? 2010 Nokia Corporation.
15
?Provides way to access sensor data
?These include
?Ambient Light
?Compass
?Proximity
?Magnetometer
?Accelerometer
?Orientation
?Rotation
?Tap
?The tap, rotation and orientation depend on the data provided by the accelerometer
Copyright ? 2010 Nokia Corporation.
16
For example, to get the acceleration to the right of the device:
QAccelerometer accSensor;
QAccelerometerReading reading = accSensor.reading();
// x is to the right of the device
qreal x = reading.x();
?Provides way to read and write Versit? documents such as vCards and vCalendar
?Allows applications to easily map QContacts to vCards and vice versa
// Parse the input into QVersitDocuments
QVersitReader reader;
reader.setDevice(&input);
reader.startReading(); // Remember to check the return value
reader.waitForFinished();
// Convert the QVersitDocuments to QContacts
QList
QVersitContactImporter importer;
if (!importer.importDocuments(inputDocuments))
return;
QList
Copyright ? 2010 Nokia Corporation.
17
Further information about Qt
Mobility API
?Qt Mobility 1.0.0 Package was released on 27th April, 2010.
?Maemo and Symbian platforms are fully supported.
?Windows CE/Mobile, Windows, Linux and Mac OS X platforms have partial
support.
?Follow the progress at Qt Mobility home page.
?For Qt Mobility Project APIs overview, compatibility information and
detailed documentation, see
?https://www.wendangku.net/doc/5f17001766.html,/qtmobility-1.0/
?For a quick overview of the purpose and the main functionality, see the Qt Mobility white paper
?https://www.wendangku.net/doc/5f17001766.html,/files/pdf/qt-mobility-whitepaper-1.0.0
Copyright ? 2010 Nokia Corporation.
18
Creating Qt Applications for Symbian, Beta
Creating Qt
Applications for
Symbian
Exercise 8
Copyright ? 2010 Nokia Corporation.
19
Creating Qt Applications for Symbian, Beta
Exercise: Hands-on lab
?See Forum Nokia's Mobile Hands-on Labs on Qt Mobility for the exercise.
Copyright ? 2010 Nokia Corporation.
20
Mobile Hands-on Labs: https://www.wendangku.net/doc/5f17001766.html,/document/Mobile_Hands-
on_Labs/Qt/MobilityLocation/