Home · All Classes · All Functions ·

QSensorBackend Class Reference

The QSensorBackend class is a sensor implementation. More...

    #include <QSensorBackend>

This class is under development and is subject to change.

Inherits QObject.


Public Functions

void newReadingAvailable ()
virtual void poll () = 0
QSensorReading * reading () const
T * setReading ( T * reading )
void setSupportedUpdatePolicies ( QSensor::UpdatePolicies policies )
virtual void start () = 0
virtual void stop () = 0

Additional Inherited Members


Detailed Description

The QSensorBackend class is a sensor implementation.

Sensors on a device will be represented by sub-classes of QSensorBackend.


Member Function Documentation

void QSensorBackend::newReadingAvailable ()

Notify the QSensor class that a new reading is available.

void QSensorBackend::poll ()   [pure virtual]

Poll the sensor for a reading.

QSensorReading * QSensorBackend::reading () const

If the backend has lost its reference to the reading it can call this method to get the address.

Note that you will need to down-cast to the appropriate type.

See also setReading().

T * QSensorBackend::setReading ( T * reading )

This function is called to initialize the reading classes used for a sensor.

If your backend has already allocated a reading you should pass the address of this to the function. Otherwise you should pass 0 and the function will return the address of the reading your backend should use when it wants to notify the sensor API of new readings.

Note that this is a template function so it should be called with the appropriate type.

    class MyBackend : public QSensorBackend
    {
        QAccelerometerReading m_reading;
    public:
        MyBackend(QSensor *sensor)
            : QSensorBackend(sensor)
        {
            setReading<QAccelerometerReading>(&m_reading);
        }

        ...

Note that this function must be called or you will not be able to send readings to the front end.

If you do not wish to store the address of the reading you may use the reading() method to get it again later.

    class MyBackend : public QSensorBackend
    {
    public:
        MyBackend(QSensor *sensor)
            : QSensorBackend(sensor)
        {
            setReading<QAccelerometerReading>(0);
        }

        void poll()
        {
            qtimestamp timestamp;
            qreal x, y, z;
            ...
            QAccelerometerReading *reading = static_cast<QAccelerometerReading*>(reading());
            reading->setTimestamp(timestamp);
            reading->setX(x);
            reading->setY(y);
            reading->setZ(z);
        }

        ...

See also reading().

void QSensorBackend::setSupportedUpdatePolicies ( QSensor::UpdatePolicies policies )

Set the supported policies for this sensor. If this isn't called the sensor will not report any supported policies to the user.

void QSensorBackend::start ()   [pure virtual]

Start reporting values.

void QSensorBackend::stop ()   [pure virtual]

Stop reporting values.


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