Home · All Classes · All Functions ·

QSensor Class Reference

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.


Public Types

flags UpdatePolicies
enum UpdatePolicy { Undefined, OnChangeUpdates, OccasionalUpdates, InfrequentUpdates, ..., PolledUpdates }

Properties


Public Functions

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

Public Slots

void start ()
void stop ()

Signals

void readingChanged ()

Related Non-Members

typedef qtimestamp

Additional Inherited Members


Detailed Description

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.


Member Type Documentation

enum QSensor::UpdatePolicy
flags QSensor::UpdatePolicies

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.

ConstantValueDescription
QSensor::Undefined0x00The 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::OnChangeUpdates0x01Updates are delivered as they happen, usually based on user activity.
QSensor::OccasionalUpdates0x02Updates are delivered occasionally, about one every 5 seconds.
QSensor::InfrequentUpdates0x04Updates are delivered infrequently, no more than once per second.
QSensor::FrequentUpdates0x08Updates are delivered frequently, several per second.
QSensor::TimedUpdates0x10Updates 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::PolledUpdates0x20Updates 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.


Property Documentation

isAvailable : const bool

This property holds the validity of the sensor.

If the sensor is not valid then you cannot use it.

Access functions:

bool isAvailable () const

reading : QSensorReading * const

This property holds the reading class.

The reading class provides access to sensor readings.

Access functions:

QSensorReading * reading () const

Notifier signal:

void readingChanged ()

running : bool

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 )

sensorid : QByteArray

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 )

supportedUpdatePolicies : const UpdatePolicies

This property holds the supported policies of the sensor.

Access functions:

UpdatePolicies supportedUpdatePolicies () const

type : QByteArray

This property holds the type of the sensor.

Access functions:

QByteArray type () const
void setType ( const QByteArray & type )

updateInterval : int

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 )

updatePolicy : UpdatePolicy

This property holds the update policy of the sensor.

Access functions:

UpdatePolicy updatePolicy () const
void setUpdatePolicy ( UpdatePolicy policy )

Member Function Documentation

QSensor::QSensor ( QObject * parent = 0 )

Construct the 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::connect ()

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().

bool QSensor::isSignalEnabled () const

Returns true if the readingChanged() signal will be emitted.

void QSensor::poll ()

Poll the sensor.

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::setSignalEnabled ( bool enabled )

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().

void QSensor::start ()   [slot]

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.

void QSensor::stop ()   [slot]

Stop retrieving values from the sensor.


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


Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies) Trademarks
Qt Mobility Project 1.0.0