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)

详细说明

要求

要在运行时申请此权限,必须在构建时声明以下特定平台用法:

平台类型
苹果使用说明NSBluetoothAlwaysUsageDescription
安卓uses-permission最高可达 Android 11(API 等级 < 31):
  • android.permission.BLUETOOTH
  • android.permission.ACCESS_FINE_LOCATION

从 Android 12(API 级别 >= 31)开始:

  • android.permission.BLUETOOTH_ADVERTISE
  • android.permission.BLUETOOTH_CONNECT
  • android.permission.BLUETOOTH_SCAN

请参阅各个使用声明类型,了解如何将它们添加到您的项目中。

注意: 自 Qt 6.8.1 起,如果 API 级别 >= 31,则不再请求 ACCESS_FINE_LOCATION 权限。这可能会限制某些蓝牙扫描结果。需要这些结果的用户需要单独申请位置权限(请参阅precise location ),并确保BLUETOOTH_SCAN 权限没有设置android:usesPermissionFlags="neverForLocation" 属性。有关在应用程序清单中设置和自定义权限的信息,请参阅本指南

另请参阅 QPermissionQCoreApplication::requestPermission() 、QCoreApplication::checkPermission() 和应用程序权限

成员类型文档

[since 6.6] 枚举 QBluetoothPermission::CommunicationMode
flags QBluetoothPermission::CommunicationModes

此枚举用于控制允许的蓝牙通信模式。

常量描述
QBluetoothPermission::Access0x01允许此设备访问其他蓝牙设备。这包括扫描附近的设备并与之连接。
QBluetoothPermission::Advertise0x02允许其他蓝牙设备发现此设备。
QBluetoothPermission::DefaultAccess | Advertise默认使用此配置。

注意: 目前只有 Android 12 及更新版本支持细粒度权限。在旧版本的安卓系统和苹果操作系统上,任何模式都会导致完全蓝牙访问。

此枚举在 Qt 6.6 中引入。

CommunicationModes 类型是QFlags<CommunicationMode> 的类型定义。它存储 CommunicationMode 值的 OR 组合。

成员函数文档

[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() 。

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