QSensorFilter Class

QSensorFilter 类为异步通知传感器变化提供了高效的回调工具。更多

头文件: #include <QSensorFilter>
CMake: find_package(Qt6 REQUIRED COMPONENTS Sensors)
target_link_libraries(mytarget PRIVATE Qt6::Sensors)
qmake: QT += sensors
继承于
13 种

QAccelerometerFilter,QAmbientLightFilter,QAmbientTemperatureFilter,QCompassFilter,QGyroscopeFilter,QHumidityFilter,QLightFilter,QMagnetometerFilter,QOrientationFilter,QPressureFilter,QProximityFilter,QRotationFilter, 和QTiltFilter

公共函数

virtual bool filter(QSensorReading *reading) = 0

受保护函数

virtual ~QSensorFilter()

详细说明

某些传感器(如加速度计)的访问频率很高。使用信号和插槽可能会降低访问速度。QSensorFilter 接口提供了一种更有效的方式,让传感器通知您的类传感器已发生变化。

此外,一个传感器可以添加多个过滤器。它们按顺序被调用,每个过滤器都可选择修改读数中的值或完全抑制读数。

请注意,QSensor::reading() 返回的类中的值在过滤器运行后才会更新。

另请参阅 filter() 。

成员函数文档

[virtual noexcept protected] QSensorFilter::~QSensorFilter()

通知所附传感器(如果有)过滤器正在被销毁。

[pure virtual] bool QSensorFilter::filter(QSensorReading *reading)

当传感器reading 发生变化时,将调用该函数。

过滤器可以修改读数。

返回 true 将允许下一个过滤器接收该值。如果这是最后一个滤波器,则返回 true 会导致信号发射并将值存储到传感器中。

返回 false 表示放弃读数。

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.