QSensorManager Class
QSensorManager 类负责处理传感器后端的注册和创建。更多内容...
| 头文件: | #include <QSensorManager> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Sensors) target_link_libraries(mytarget PRIVATE Qt6::Sensors) |
| qmake: | QT += sensors |
静态公共成员
| QSensorBackend * | createBackend(QSensor *sensor) |
| bool | isBackendRegistered(const QByteArray &type, const QByteArray &identifier) |
| void | registerBackend(const QByteArray &type, const QByteArray &identifier, QSensorBackendFactory *factory) |
| void | setDefaultBackend(const QByteArray &type, const QByteArray &identifier) |
| void | unregisterBackend(const QByteArray &type, const QByteArray &identifier) |
成员函数文档
[static] QSensorBackend *QSensorManager::createBackend(QSensor *sensor)
为sensor 创建一个后端。如果不存在合适的后端,则返回 null。
[static] bool QSensorManager::isBackendRegistered(const QByteArray &type, const QByteArray &identifier)
如果由type 和identifier 标识的后端已注册,则返回 true。
这是一个便捷方法,用于协助插件进行动态注册。
[static] void QSensorManager::registerBackend(const QByteArray &type, const QByteArray &identifier, QSensorBackendFactory *factory)
为type 注册一个传感器。identifier 必须是唯一的。
系统将要求factory 创建后端实例。
在选择默认传感器时,如果检测到其他传感器,以generic 或dummy 开头的传感器标识符将被赋予较低优先级。
[static] void QSensorManager::setDefaultBackend(const QByteArray &type, const QByteArray &identifier)
使用后端identifier 设置或覆盖传感器type 。
[static] void QSensorManager::unregisterBackend(const QByteArray &type, const QByteArray &identifier)
使用 `identifier` 取消注册type 的后端。
请注意,此操作仅会阻止创建该后端的新实例,不会使现有的后端实例失效。后端代码应自行处理底层硬件消失的情况。
© 2026 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.