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  · 

QSensor Class Reference

The QSensor class represents a single hardware sensor. More...

    #include <QSensor>

Inherits QObject.

Inherited by QAccelerometer, QAmbientLightSensor, QCompass, QMagnetometer, QOrientationSensor, QProximitySensor, QRotationSensor, and QTapSensor.


Properties

  • 1 property inherited from QObject

Public Functions

QSensor ( const QByteArray & type, QObject * parent = 0 )
virtual ~QSensor ()
void addFilter ( QSensorFilter * filter )
qrangelist availableDataRates () const
bool connectToBackend ()
int dataRate () const
QString description () const
int error () const
QByteArray identifier () const
bool isActive () const
bool isBusy () const
bool isConnectedToBackend () const
int outputRange () const
qoutputrangelist outputRanges () const
QSensorReading * reading () const
void removeFilter ( QSensorFilter * filter )
void setDataRate ( int rate )
void setIdentifier ( const QByteArray & identifier )
void setOutputRange ( int index )
QByteArray type () const
  • 29 public functions inherited from QObject

Public Slots

bool start ()
void stop ()
  • 1 public slot inherited from QObject

Signals

void busyChanged ()
void readingChanged ()
void sensorError ( int error )

Static Public Members

QByteArray defaultSensorForType ( const QByteArray & type )
QList<QByteArray> sensorTypes ()
QList<QByteArray> sensorsForType ( const QByteArray & type )
  • 4 static public members inherited from QObject

Related Non-Members

typedef qtimestamp

Additional Inherited Members

  • 1 public type inherited from QObject
  • 7 protected functions inherited from QObject
  • 2 protected variables inherited from QObject

Detailed Description

The QSensor class represents a single hardware sensor.

The life cycle of a sensor is typically:

  • Create a sub-class of QSensor on the stack or heap.
  • Setup as required by the application.
  • Start receiving values.
  • Sensor data is used by the application.
  • Stop receiving values.

The sensor data is delivered via QSensorData and its sub-classes.


Property Documentation

active : const bool

This property holds a value to indicate if the sensor is active.

This is true if the sensor is active (returning values). This is false otherwise.

Access functions:

bool isActive () const

availableDataRates : const QtMobility::qrangelist

This property holds the data rates that the sensor supports.

This is a list of the data rates that the sensor supports. Measured in Hertz.

Entries in the list can represent discrete rates or a continuous range of rates. A discrete rate is noted by having both values the same.

See the sensor_explorer example for an example of how to interpret and use this information.

Access functions:

qrangelist availableDataRates () const

See also QSensor::dataRate.

busy : const bool

This property holds a value to indicate if the sensor is busy.

Some sensors may be on the system but unavailable for use. This function will return true if the sensor is busy. You will not be able to start() the sensor.

Note that this function does not return true if you are using the sensor, only if another process is using the sensor.

Access functions:

bool isBusy () const

See also busyChanged().

connectedToBackend : const bool

This property holds a value indicating if the sensor has connected to a backend.

A sensor that has not been connected to a backend cannot do anything useful.

Call the connectToBackend() method to force the sensor to connect to a backend immediately. This is automatically called if you call start() so you only need to do this if you need access to sensor properties (ie. to poll the sensor's meta-data before you use it).

Access functions:

bool isConnectedToBackend () const

dataRate : int

This property holds the data rate that the sensor should be run at.

Measured in Hertz.

The data rate is the maximum frequency at which the sensor can detect changes.

Setting this property is not portable and can cause conflicts with other applications. Check with the sensor backend and platform documentation for any policy regarding multiple applications requesting a data rate.

The default value (0) means that the app does not care what the data rate is. Applications should consider using a timer-based poll of the current value or ensure that the code that processes values can run very quickly as the platform may provide updates hundreds of times each second.

This should be set before calling start() because the sensor may not notice changes to this value while it is running.

Note that there is no mechanism to determine the current data rate in use by the platform.

Access functions:

int dataRate () const
void setDataRate ( int rate )

See also QSensor::availableDataRates.

description : const QString

This property holds a descriptive string for the sensor.

Access functions:

QString description () const

error : const int

This property holds the last error code set on the sensor.

Note that error codes are sensor-specific.

Access functions:

int error () const

Notifier signal:

void sensorError ( int error )

outputRange : int

This property holds the output range in use by the sensor.

This value represents the index in the QSensor::outputRanges list to use.

Setting this property is not portable and can cause conflicts with other applications. Check with the sensor backend and platform documentation for any policy regarding multiple applications requesting an output range.

The default value (-1) means that the app does not care what the output range is.

Note that there is no mechanism to determine the current output range in use by the platform.

Access functions:

int outputRange () const
void setOutputRange ( int index )

See also QSensor::outputRanges.

outputRanges : const QtMobility::qoutputrangelist

This property holds a list of output ranges the sensor supports.

A sensor may have more than one output range. Typically this is done to give a greater measurement range at the cost of lowering accuracy.

Access functions:

qoutputrangelist outputRanges () const

See also QSensor::outputRange.

reading : QSensorReading * const

This property holds the reading class.

The reading class provides access to sensor readings.

Note that this will return 0 until a sensor backend is connected to a backend.

Access functions:

QSensorReading * reading () const

Notifier signal:

void readingChanged ()

See also isConnectedToBackend().

sensorid : QByteArray

This property holds the backend identifier for the sensor.

Note that the identifier is filled out automatically when the sensor is connected to a backend. If you want to connect a specific backend, you should call setIdentifier() before connectToBackend().

Access functions:

QByteArray identifier () const
void setIdentifier ( const QByteArray & identifier )

type : const QByteArray

This property holds the type of the sensor.

Access functions:

QByteArray type () const

Member Function Documentation

QSensor::QSensor ( const QByteArray & type, QObject * parent = 0 )

Construct the type sensor as a child of parent.

QSensor::~QSensor ()   [virtual]

Destroy the sensor. Stops the sensor if it has not already been stopped.

void QSensor::addFilter ( QSensorFilter * filter )

Add a filter to the sensor.

The sensor does not take ownership of the filter. QSensorFilter will inform the sensor if it is destroyed.

See also QSensorFilter.

void QSensor::busyChanged ()   [signal]

This signal is emitted when the busy state changes. This can be used to grab a sensor when it becomes available.

bool QSensor::connectToBackend ()

Try to connect to a sensor backend.

Returns true if a suitable backend could be found, false otherwise.

The type must be set before calling this method if you are using QSensor directly.

See also isConnectedToBackend().

QByteArray QSensor::defaultSensorForType ( const QByteArray & type )   [static]

Returns the default sensor identifier for type. This is set in a config file and can be overridden if required. If no default is available the system will return the first registered sensor for type.

void QSensor::readingChanged ()   [signal]

This signal is emitted when the reading has changed.

void QSensor::removeFilter ( QSensorFilter * filter )

Remove filter from the sensor.

See also QSensorFilter.

void QSensor::sensorError ( int error )   [signal]

This signal is emitted when an error code is set on the sensor. Note that some errors will cause the sensor to stop working. You should call isActive() to determine if the sensor is still running.

QList<QByteArray> QSensor::sensorTypes ()   [static]

Returns a list of all sensor types.

QList<QByteArray> QSensor::sensorsForType ( const QByteArray & type )   [static]

Returns a list of ids for each of the sensors for type. If there are no sensors of that type available the list will be empty.

bool QSensor::start ()   [slot]

Start retrieving values from the sensor. Returns true if the sensor was started, false otherwise.

Note that the sensor may fail to start for several reasons.

See also QSensor::busy.

void QSensor::stop ()   [slot]

Stop retrieving values from the sensor.

This releases the sensor so that other processes can use it.

See also QSensor::busy.


Related Non-Members

typedef qtimestamp

Sensor timestamps are represented by this typedef which is a 64 bit unsigned integer.

Timestamps values are microseconds since a fixed point. You can use timestamps to see how far apart two sensor readings are.

Note that sensor timestamps from different sensors may not be directly comparable (as they may choose different fixed points for their reference).

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 85
  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. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 19
  6. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  7. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
Page suivante

Le blog Digia au hasard

Logo

Créer des applications avec un style Metro avec Qt, exemples en QML et C++, un article de Digia Qt traduit par Thibaut Cuvelier

Le blog Digia est l'endroit privilégié pour la communication sur l'édition commerciale de Qt, où des réponses publiques sont apportées aux questions les plus posées au support. 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