QBluetoothPermission Class
访问蓝牙外设。更多...
| 标题: | #include <QPermissions> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
| 自: | Qt 6.5 |
公共类型
(since 6.6) enum | CommunicationMode { Access, Advertise, Default } |
| flags | CommunicationModes |
公共函数
(since 6.6) QBluetoothPermission::CommunicationModes | communicationModes() const |
(since 6.6) void | setCommunicationModes(QBluetoothPermission::CommunicationModes modes) |
详细说明
要求
要在运行时请求此权限,必须在构建时进行以下特定于平台的使用声明:
| 平台 | 类型 | |
|---|---|---|
| Apple | 用法说明 | NSBluetoothAlwaysUsageDescription |
| Android | uses-permission | Android 11及以下版本(API级别 < 31):
从 Android 12(API 级别 >= 31)开始:
|
有关如何将它们添加到项目中,请参阅各使用声明类型的说明。
注意:自 Qt 6.8.1起 ,若 API 级别 >= 31,将不再请求 ACCESS_FINE_LOCATION 权限。这可能会限制部分蓝牙扫描结果。 需要这些扫描结果的用户需单独请求位置权限(参见precise location ),并确保BLUETOOTH_SCAN 权限未设置android:usesPermissionFlags="neverForLocation" 属性。有关在应用程序清单中设置和自定义权限的说明,请参阅本指南。
另请参阅 QPermission 、QCoreApplication::requestPermission()、QCoreApplication::checkPermission() 以及“应用程序权限”。
成员类型文档
[since 6.6] enum QBluetoothPermission::CommunicationMode
flags QBluetoothPermission::CommunicationModes
此枚举用于控制允许的蓝牙通信模式。
| 常量 | 值 | 描述 |
|---|---|---|
QBluetoothPermission::Access | 0x01 | 允许此设备访问其他蓝牙设备。这包括扫描附近设备并与其连接。 |
QBluetoothPermission::Advertise | 0x02 | 允许其他蓝牙设备发现此设备。 |
QBluetoothPermission::Default | Access | Advertise | 此配置为默认设置。 注意: 精细化权限 目前仅在 Android 12 及更高版本上受支持。在较旧的 Android 版本以及 Apple 操作系统上,无论选择哪种模式,都会授予完整的蓝牙访问权限。 |
该枚举类型在 Qt 6.6 中引入。
CommunicationModes 类型是QFlags<CommunicationMode> 的 typedef。它存储 CommunicationMode 值的按“或”运算组合。
成员函数文档
[since 6.6] QBluetoothPermission::CommunicationModes QBluetoothPermission::communicationModes() const
返回允许的蓝牙通信模式。
该函数自 Qt 6.6 起引入。
另请参阅 setCommunicationModes()。
[since 6.6] void QBluetoothPermission::setCommunicationModes(QBluetoothPermission::CommunicationModes modes)
将允许的蓝牙通信模式设置为modes 。
注意: CommunicationModes 的默认构造实例没有实际意义,因此尝试设置此类模式将引发qWarning() 异常,并回退到使用Default 模式。
该函数于 Qt 6.6 中引入。
另请参阅 communicationModes()。
© 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.