QSensorBackend 类

QSensorBackend 类是传感器实现。 更多...

头: #include <QSensorBackend>
CMake: find_package(Qt6 COMPONENTS Sensors REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Sensors)
qmake: QT += sensors
Since: Qt 5.1
继承: QObject

公共函数

void addDataRate (qreal min , qreal max )
void addOutputRange (qreal min , qreal max , qreal accuracy )
virtual bool isFeatureSupported (QSensor::Feature feature ) const
void newReadingAvailable ()
QSensorReading * reading () const
QSensor * sensor () const
void sensorBusy (bool busy = true)
void sensorError (int error )
void sensorStopped ()
void setDataRates (const QSensor * otherSensor )
void setDescription (const QString & description )
T * setReading (T * reading )
virtual void start () = 0
virtual void stop () = 0

详细描述

设备传感器将由 QSensorBackend 子类所表示。

成员函数文档编制

void QSensorBackend:: addDataRate ( qreal min , qreal max )

Add a data rate (consisting of min and max values) for the sensor.

Note that this function should be called from the constructor so that the information is available immediately.

另请参阅 QSensor::availableDataRates .

void QSensorBackend:: addOutputRange ( qreal min , qreal max , qreal accuracy )

Add an output range (consisting of min , max values and accuracy ) for the sensor.

Note that this function should be called from the constructor so that the information is available immediately.

另请参阅 QSensor::outputRange and QSensor::outputRanges .

[virtual, since 5.0] bool QSensorBackend:: isFeatureSupported ( QSensor::Feature feature ) const

校验特征是否由此传感器后端所支持。

这是后端侧的 QSensor::isFeatureSupported (). Reimplement this function if the backend supports one of the additional sensor features of QSensor::Feature .

Returns whether the feature feature is supported by this backend. The default implementation returns false.

该函数在 Qt 5.0 引入。

void QSensorBackend:: newReadingAvailable ()

Notify the QSensor class that a new reading is available.

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.

另请参阅 setReading ().

QSensor *QSensorBackend:: sensor () const

Returns the sensor front end associated with this backend.

void QSensorBackend:: sensorBusy ( bool busy = true)

Inform the front end of the sensor's busy state according to the provided busy 参数。

If the sensor is set busy this implicitly calls sensorStopped (). Busy indication is typically done in start ().

Note that the front end must call QSensor::isBusy () to see if the sensor is busy. If the sensor has stopped due to an error the sensorError () function should be called to notify the class of the error condition.

void QSensorBackend:: sensorError ( int error )

Inform the front end that a sensor error occurred. Note that this only reports an error code. It does not stop the sensor.

另请参阅 sensorStopped ().

void QSensorBackend:: sensorStopped ()

Inform the front end that the sensor has stopped. This can be due to start () failing or for some unexpected reason (eg. hardware failure).

Note that the front end must call QSensor::isActive () to see if the sensor has stopped. If the sensor has stopped due to an error the sensorError () function should be called to notify the class of the error condition.

void QSensorBackend:: setDataRates (const QSensor * otherSensor )

Set the data rates for the sensor based on otherSensor .

This is designed for sensors that are based on other sensors.


 setDataRates(otherSensor);
					

Note that this function must be called from the constructor.

另请参阅 QSensor::availableDataRates and addDataRate ().

void QSensorBackend:: setDescription (const QString & description )

设置 description 为传感器。

Note that this function should be called from the constructor so that the information is available immediately.

template <typename T> 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()
     {
         quint64 timestamp;
         qreal x, y, z;
         ...
         QAccelerometerReading *reading = static_cast<QAccelerometerReading*>(reading());
         reading->setTimestamp(timestamp);
         reading->setX(x);
         reading->setY(y);
         reading->setZ(z);
     }
     ...
					

另请参阅 reading ().

[pure virtual] void QSensorBackend:: start ()

开始报告值。

[pure virtual] void QSensorBackend:: stop ()

停止报告值。