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  · 

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.

  1. Select File > New File or Project > Qt Application Project > Mobile Qt Application > Choose.

    "New File or Project dialog"

    The Introduction and Project Location dialog opens.

    "Introduction and Project Location dialog"

  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.

    The Select Required Qt Versions dialog opens.

    "Select Required Qt Versions dialog"

  4. 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.

    "Class Information dialog"

  5. In the Class Name field, type BatteryIndicator as the class name.
  6. 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.

  7. Click Next.

    The Project Management dialog opens.

    "Project Management dialog"

  8. Review the project settings, and click Finish to create the project.

The BatteryIndicator project now contains the following files:

  • batteryindicator.h
  • batteryindicator.cpp
  • main.cpp
  • batteryindicator.ui
  • BatteryIndicator.pro

"Project contents"

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
 }

Designing the User Interface

  1. In the Editor mode, double-click the batteryindicator.ui file in the Projects view to launch the integrated Qt Designer.
  2. Drag and drop a Progress Bar (QProgressBar) widget to the form.

    "Adding widgets to the UI"

  3. 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.

  1. In the Projects view, double-click the batteryindicator.h file to open it for editing.
  2. Include the System Info header file, as illustrated by the following code snippet:
     #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:
     private:
         Ui::BatteryIndicator *ui;
         void setupGeneral();
    
         QSystemDeviceInfo *deviceInfo;

Completing the Source File

Now that the header file is complete, move on to the source file, batteryindicator.cpp.

  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:
     void BatteryIndicator::setupGeneral()
     {
         deviceInfo = new QSystemDeviceInfo(this);
    
         ui->batteryLevelBar->setValue(deviceInfo->batteryLevel());
    
         connect(deviceInfo, SIGNAL(batteryLevelChanged(int)),
                 ui->batteryLevelBar, SLOT(setValue(int)));
     }
  3. 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) :
         QDialog(parent),
         ui(new Ui::BatteryIndicator),
         deviceInfo(NULL)
     {
         ui->setupUi(this);
         setupGeneral();
     }

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.

"Mobile example in Qt Simulator"

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.

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.

X

rc="scripts/functions.js" type="text/javascript">
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 64
  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. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  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. La rubrique Qt a besoin de vous ! 1
Page suivante

Le Qt Developer Network au hasard

Logo

Comment fermer une application

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. 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 qtcreator-2.0
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