本页内容

兼容性图表

颜色 说明
该传感器受支持。
该传感器不受支持。
功能 Android Linux iOS Windows 通用
加速度计
环境光传感器
环境温度传感器
指南针
陀螺仪
光传感器
磁力计
方位传感器
压力传感器
接近传感器
旋转传感器
倾斜传感器

除上表所示外,每种传感器类型可能还支持特定功能。例如,磁力计可能支持返回地理坐标值。更多详情请参阅QSensor::isFeatureSupported()。

平台特定说明

Windows

在由 MSVC 构建的 Qt 安装中支持 Windows 后端。

Android

无需请求任何 Android 权限即可读取 Android 后端提供的传感器数据。

唯一的限制涉及加速度计、陀螺仪和磁力计的采样率。 从 Android 12(API 级别 31)开始,若以高于 200 Hz 的采样率读取这些传感器,则需要“android.permission.HIGH_SAMPLING_RATE_SENSORS ”权限。这属于常规权限,会在安装时自动授予,无需向用户提示。若未声明该权限,采样率将被限制在 200 Hz 以内。

使用qt_add_android_permission 为应用程序声明该权限:

qt_add_android_permission(myapp
    NAME android.permission.HIGH_SAMPLING_RATE_SENSORS
)

注意:若使用 手动编写的 AndroidManifest.xml 文件,必须包含<!-- %%INSERT_PERMISSIONS --> 标签才能添加该权限。请参阅《Qt 权限与功能》。

HarmonyOS

HarmonyOS 上的某些传感器在读取其数据之前需要获得权限:

HarmonyOS 后端提供的其他传感器(光传感器、磁力计和旋转传感器)无需任何权限即可读取。

若尝试订阅未获授权的传感器,操作将失败,且不会收到任何读数。

请使用 `qt_add_harmonyos_permission` 为应用声明权限:

qt_add_harmonyos_permission(myapp
    NAME ohos.permission.ACCELEROMETER
)

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