![]() |
Home · All Classes · All Functions · | ![]() |
The QSensor class represents a single hardware sensor. More...
#include <QSensor>
This class is under development and is subject to change.
Inherits QObject.
Inherited by QAccelerometer, QAmbientLightSensor, QCompass, QMagnetometer, QOrientationSensor, QProximitySensor, QRotationSensor, and QTapSensor.
flags | UpdatePolicies |
enum | UpdatePolicy { Undefined, OnChangeUpdates, OccasionalUpdates, InfrequentUpdates, ..., PolledUpdates } |
|
|
QSensor ( QObject * parent = 0 ) | |
virtual | ~QSensor () |
void | addFilter ( QSensorFilter * filter ) |
void | connect () |
QByteArray | identifier () const |
bool | isActive () const |
bool | isAvailable () const |
bool | isSignalEnabled () const |
void | poll () |
QSensorReading * | reading () const |
void | removeFilter ( QSensorFilter * filter ) |
void | setActive ( bool running ) |
void | setIdentifier ( const QByteArray & identifier ) |
void | setSignalEnabled ( bool enabled ) |
void | setType ( const QByteArray & type ) |
void | setUpdateInterval ( int interval ) |
void | setUpdatePolicy ( UpdatePolicy policy ) |
UpdatePolicies | supportedUpdatePolicies () const |
QByteArray | type () const |
int | updateInterval () const |
UpdatePolicy | updatePolicy () const |
void | start () |
void | stop () |
void | readingChanged () |
typedef | qtimestamp |
The QSensor class represents a single hardware sensor.
The life cycle of a sensor is typically:
The sensor data is delivered via QSensorData and its sub-classes.
This enum is used to indicate to the sensor how often data will be collected. Note that most sensors will only support one sensitivity. Setting an update policy that the sensor does not support will result in undefined behaviour. You can determine the policies the sensor supports with the QSensor::supportedUpdatePolicies() method.
Constant | Value | Description |
---|---|---|
QSensor::Undefined | 0x00 | The sensor has no specific update policy. Updates may arrive frequently or infrequently. Updates based on user interaction are likely to fit into this category. |
QSensor::OnChangeUpdates | 0x01 | Updates are delivered as they happen, usually based on user activity. |
QSensor::OccasionalUpdates | 0x02 | Updates are delivered occasionally, about one every 5 seconds. |
QSensor::InfrequentUpdates | 0x04 | Updates are delivered infrequently, no more than once per second. |
QSensor::FrequentUpdates | 0x08 | Updates are delivered frequently, several per second. |
QSensor::TimedUpdates | 0x10 | Updates are delivered at a specific time interval. Note that not all sensors may be able to run with the exact timings requested and may operate slightly faster or slower. |
QSensor::PolledUpdates | 0x20 | Updates are retrieved when the currentReading() method is called. |
The UpdatePolicies type is a typedef for QFlags<UpdatePolicy>. It stores an OR combination of UpdatePolicy values.
This property holds the validity of the sensor.
If the sensor is not valid then you cannot use it.
Access functions:
bool | isAvailable () const |
This property holds the reading class.
The reading class provides access to sensor readings.
Access functions:
QSensorReading * | reading () const |
Notifier signal:
void | readingChanged () |
This property holds controls the running state of the sensor.
This is provided for QML, set running: true to cause the sensor to start on.
Access functions:
bool | isActive () const |
void | setActive ( bool running ) |
This property holds the backend identifier for the sensor.
Note if the sensor is not connected to a backend the identifier may be empty.
Access functions:
QByteArray | identifier () const |
void | setIdentifier ( const QByteArray & identifier ) |
This property holds the supported policies of the sensor.
Access functions:
UpdatePolicies | supportedUpdatePolicies () const |
This property holds the type of the sensor.
Access functions:
QByteArray | type () const |
void | setType ( const QByteArray & type ) |
This property holds the update interval of the sensor.
This value is only useful if the QSensor::updatePolicy property is set to TimedUpdates.
Access functions:
int | updateInterval () const |
void | setUpdateInterval ( int interval ) |
This property holds the update policy of the sensor.
Access functions:
UpdatePolicy | updatePolicy () const |
void | setUpdatePolicy ( UpdatePolicy policy ) |
Construct the sensor as a child of parent.
Destroy the sensor. Stops the sensor if it has not already been stopped.
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.
Try to connect to a sensor backend.
You can test for failure with the isAvailable() function.
The type must be set before calling this method if you are using QSensor directly.
See also isAvailable().
Returns true if the readingChanged() signal will be emitted.
Poll the sensor.
This signal is emitted when the reading has changed.
Remove filter from the sensor.
See also QSensorFilter.
Call with enabled as false to turn off the readingChanged() signal.
You might want to do this for performance reasons. If you are polling the sensor or using a filter in a performance-critical application then the overhead of emitting the signal may be too high even if nothing is connected to it.
See also isSignalEnabled().
Start retrieving values from the sensor.
Note that some sensors require exclusive access so this function may fail and return false.
Also note that some sensors may not honour settings set after this method is called.
Stop retrieving values from the sensor.
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).
Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies) | Trademarks | Qt Mobility Project 1.0.0 |