Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

Quickstart guide

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 QtMobility with 3 simple steps.

  1. Include the appropriate headers
  2. Use the QTM_USE_NAMESPACE macro (defined in qmobilityglobal.h but implicitly included from any QtMobility header)
  3. Declare the usage of QtMobility and appropriate API(s) in the project(.pro) file

Steps 1 and 2 are shown in the example below:

 #include <QApplication>
 #include <QLabel>

 #include <QSystemInfo> //(1)

 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.

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.

DomainValue
Bearer Managementbearer
Contactscontacts
Locationlocation
Multimediamultimedia
Messagingmessaging
Publish And Subscribepublishsubscribe
Service Frameworkserviceframework
Sensorssensors
System Informationsysteminfo
Versitversit
Document Gallerygallery
Organizerorganizer
Tactile Feedbackfeedback

In addition the Mobility version and installed modules can be checked from within qmake project files. The associated module name for such tests is the same as above:

 load(mobilityconfig)
 contains(MOBILITY_VERSION, 1.1.1) {
     message(Mobility 1.1.1 detected)
 }
 contains(MOBILITY_CONFIG, contacts) {
     message(Contacts API available)
     CONFIG+=mobility
     MOBILITY+=contacts
 } else {
     message(Contacts API not available)
 }

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. This can be achieved with a line such as the following:

 TARGET.CAPABILITY = CAPABILITY_A CABAPILITY_B

CAPABILITY_A and CAPABILITY_B are place holders for the appropriate Symbian capabilities. A complete list of all Symbian capabilities and their availability to application developers can be found in the Forum Nokia Symbian capability documentation.

The subsequent table provides an overview of possibily required security tokens for each QtMobility library. Note that not all tokens are always required when using a particular API. The exact list depends on which parts of an API is utilized by an application.

DomainSymbian CapabilitiesHarmattan Tokens (Aegis)
Bearer ManagementReadUserData NetworkServices (NetworkControl for QNetworkSession::stop())No token requirements known at this stage.
Connectivity - NFCLocalServicesNo token requirements known at this stage.
Connectivity - BluetoothLocalServices NetworkServices (ReadDeviceData WriteDeviceData for Pairing control)No token requirements known at this stage.
ContactsReadUserData WriteUserDataTrackerReadAccess TrackerWriteAccess GRP::metadata-users
LocationLocation LocalServices ReadUserData WriteUserData ReadDeviceData WriteDeviceData NetworkServicesLocation TrackerReadAccess TrackerWriteAccess
MultimediaUserEnvironment ReadUserData WriteUserData ReadDeviceData WriteDeviceDataGRP::video GRP::pulse-access
MessagingLocalServices ReadUserData WriteUserData NetworkServices UserEnvironment ReadDeviceData WriteDeviceDataCellular TrackerReadAccess
Publish And SubscribeCapability depends on P&S value being read/written. API itself doesn't require any capability.No token requirements known at this stage.
Service FrameworkNo capabilities requried by itself, the plugins may have capability requirements.No token requirements known at this stage.
SensorReadDeviceDataNo token requirements known at this stage.
System InformationLocalServices ReadUserData WriteUserData NetworkServices UserEnvironment Location ReadDeviceDatamce::TKLockControl mce::DeviceModeControl
VersitNo additional capabilities required.No token requirements known at this stage.
Document GalleryReadDeviceData WriteDeviceDataTrackerReadAccess TrackerWriteAccess
OrganizerReadUserData WriteUserDataTrackerReadAccess TrackerWriteAccess GRP::calendar GRP::metadata-users
Tactile FeedbackNo capabilities at this stage.No token requirements known at this stage.

The complete list of all Symbian capabilities and how they can be obtained can be found at Forum Nokia Symbian capability documentation.

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 for Symbian

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 94
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 41
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 6
Page suivante

Le Qt Labs au hasard

Logo

Améliorer les performances de Qt lors du rendu avec plus de SIMD

Les Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt qtmobility-1.2
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web