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  · 

Sensors API

The Sensors API provides access to sensors.

This covers both high-level sensors such as screen orientation (portrait, landscape) and low-level, real-time sensors such as accelerometer data.

Namespace

The QtMobility APIs are placed into the QtMobility namespace. This is done to facilitate the future migration of Mobility APIs into Qt. See the Quickstart guide for an example on how the namespace impacts on application development.

Sensor Types

On a device there can be many types of sensors. Not all of the types that the Sensors API supports may be available. There may also be types available that are not defined in the Sensors API. You can find the sensor types available on a device using the QSensor::sensorTypes() function.

For a list of built-in sensor types, see the Sensor Classes section below.

Common Conventions

Unless otherwise specified, sensors shall use the Right Hand Cartesian coordinate system.

To allow for measurements in all 6 directions, negative values are used.

Where rotation around an axis is used, the rotation shall be expressed as a Right Hand rotation.

In general, sensor data is oriented to the top of the device. If values are to be displayed on the screen the values may need to be transformed so that they match the user interface orientation. A sensor may define its data as being oriented to the UI. This will be noted in the documentation for the sensor.

Using a Sensor

The life cycle of a sensor is typically:

  • Create an instance of QSensor or one of its sub-classes on the stack or heap.
  • Setup as required by the application.
  • Start receiving values.
  • Sensor data is used by the application.
  • Stop receiving values.

Here is an example of creating a sensor on the heap and on the stack.

    // On the heap (deleted when this object is deleted)
    QAccelerometer *sensor = new QAccelerometer(this);

    // On the stack (deleted when the current scope ends)
    QOrientationSensor orient_sensor;

Accessing sensor data in a generic fashion

The preferred way to deal with sensor data is via the Reading Classes. However, sometimes this may not be possible. For example, you may be deploying an application to a device that has a new sensor type but no C++ header describing the reading class is available.

Thanks to Qt's property system you can still access the sensor data. You need to know 3 pieces of information in order to do this:

  • The sensor type.
  • The property name or index.
  • The property type or a comparable type.

For example, here is an example of how you can access a property of the accelerometer. This code does not require any compile-time links to QAccelerometer or QAccelerometerReading.

    // start the sensor
    QSensor sensor("QAccelerometer");
    sensor.start();

    // later
    QSensorReading *reading = sensor.reading();
    qreal x = reading->property("x").value<qreal>();
    qreal y = reading->value(1).value<qreal>();

You can discover all of this information at runtime too. The sensor_explorer example shows you information about available sensors.

Front end, back end

The Sensors API has a front end, for application developers to use and a back end, where device implementors write code to access their hardware. As an application developer you do not need to access the back end though it may be useful to understand how it works.

Commands from the application are delivered through QSensor and then down to the device plugin. Data comes back through the QSensorReading class.

More information about the back end can be found in Sensors Backend.

Main Classes

The primary classes that make up the Sensors API.

QSensorRepresents a single hardware sensor
QSensorFilterEfficient callback facility for asynchronous notifications of sensor changes
QSensorReadingHolds the readings from the sensor

Reading Classes

The best way to access sensor data is via one of these classes.

QAccelerometerReadingReports on linear acceleration along the X, Y and Z axes
QAmbientLightReadingRepresents one reading from the ambient light sensor
QCompassReadingRepresents one reading from a compass
QMagnetometerReadingRepresents one reading from the magnetometer
QOrientationReadingRepresents one reading from the orientation sensor
QProximityReadingRepresents one reading from the proximity sensor
QRotationReadingRepresents one reading from the rotation sensor
QTapReadingRepresents one reading from the tap sensor

Sensor Classes

These classes provide convenience wrappers that reduce the need for casting. Each of these classes represents a sensor type that the Sensors API knows about. Note that additional types may be made available at run-time. See Sensor Types for more information.

QAccelerometerConvenience wrapper around QSensor
QAmbientLightSensorConvenience wrapper around QSensor
QCompassConvenience wrapper around QSensor
QMagnetometerConvenience wrapper around QSensor
QOrientationSensorConvenience wrapper around QSensor
QProximitySensorConvenience wrapper around QSensor
QRotationSensorConvenience wrapper around QSensor
QTapSensorConvenience wrapper around QSensor

Filter Classes

As with the sensor classes, these provide convenience wrappers that reduce the need for casting.

QAccelerometerFilterConvenience wrapper around QSensorFilter
QAmbientLightFilterConvenience wrapper around QSensorFilter
QCompassFilterConvenience wrapper around QSensorFilter
QMagnetometerFilterConvenience wrapper around QSensorFilter
QOrientationFilterConvenience wrapper around QSensorFilter
QProximityFilterConvenience wrapper around QSensorFilter
QRotationFilterConvenience wrapper around QSensorFilter
QTapFilterConvenience wrapper around QSensorFilter

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. Microsoft ouvre aux autres compilateurs C++ AMP, la spécification pour la conception d'applications parallèles C++ utilisant le GPU 22
  2. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  3. RIM : « 13 % des développeurs ont gagné plus de 100 000 $ sur l'AppWord », Qt et open-source au menu du BlackBerry DevCon Europe 0
  4. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 10
  5. 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
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
Page suivante

Le Qt Quarterly au hasard

Logo

Déployer dans le Bazaar

Qt Quarterly est la revue trimestrielle proposée par Nokia et à destination des développeurs Qt. Ces articles d'une grande qualité technique sont rédigés par des experts Qt. 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.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