Qt Bluetooth

Qt 6 的改动是有意识地使框架更高效、更易用的结果。

我们尝试在每个版本中保持所有公共 API 的二进制和源代码兼容性。但为了使 Qt 成为一个更好的框架,有些改动是不可避免的。

在本专题中,我们总结了QtBluetooth 中的这些变化,并提供了处理这些变化的指南。

概述

  • 删除了 qbluetoothglobal.h。qtbluetoothglobal.h 是具有相同目的的官方头文件。
  • QVector 的所有用法均由QList 代替。
  • 删除了 Win32 后端。在使用 mingw 构建 Qt 时,将不会有可用的蓝牙后端。
  • 由于现在只有一个 Windows 后端,日志类别 qt.Bluetooth.winrt 已被移除。相应的日志信息现在在 qt.Bluetooth.windows 中。

QBluetooth 命名空间

为提高类型安全性,枚举QBluetooth::SecurityQBluetooth::AttAccessConstraint 已更改为作用域枚举。

QBluetoothDeviceDiscoveryAgent

删除了 QBluetoothDeviceDiscoveryAgent::inquiryType 属性和相关的 setter/getter & 枚举。从未实现和/或支持该 API 元素。

QBluetoothDeviceInfo

  • manufacturerData() 返回QMultiHash ,而不是QHash 。自 Qt XML 6 起,QMultiHash 不再从QHash 派生。
  • 由于相关的 API 元素不再起作用,因此删除了 DataCompleteness 而没有进行替换
  • setServiceUuids(constQList<QBluetoothUuid>, DataCompleteness) 被 setServiceUuids(constQList<QBluetoothUuid> &uuids) 取代。
  • 删除了 DataCompleteness serviceUuidsCompleteness() 常量,但未作替换。
  • QList<QBluetoothUuid> serviceUuids(DataCompleteness *completeness = nullptr) const 被QList<QBluetoothUuid> serviceUuids() const 取代。

QBluetoothLocalDevice

配对代理相关的 API 被移除,没有替换。其中包括 pairingConfirmation(bool)、pairingDisplayPinCode(..) 和 pairingDisplayConfirmation(..)。除了 Android 和 BlueZ 4 之外,从未有其他实现。Qt 6 取消了对 Bluez 4 的支持,而 Android 的实现至少在部分代码中要求使用无法获得的 BLUETOOTH_PRIVILEGED。

QLowEnergyService

重命名了 ServiceState 枚举值:

这一更改是考虑到服务发现将来可能成为一个可选步骤。

QBluetoothUuid

枚举ProtocolUuidServiceClassUuidCharacteristicTypeDescriptorType 现在是作用域枚举。用户代码中必须调整枚举项的用法。

QLowEnergyController

QLowEnergyCharacteristic

  • 引入了新方法 clientCharacteristicConfiguration(),以便于获取客户端特性配置描述符。
  • 引入了常量CCCDDisableCCCDEnableNotificationCCCDEnableIndication ,用于保存客户特性配置描述符的可能值。
  • handle() 方法不再是公共蓝牙 LE 接口的一部分。它作为特性标识符的作用已被取代。QLowEnergyCharacteristic 实例本身就是标识符。

QLowEnergyDescriptor

handle() 方法不再是公共蓝牙 LE 接口的一部分。它作为描述符标识符的作用已被取代。QLowEnergyDescriptor 实例本身就是标识符。

QBluetooth 传输管理器

QBluetoothTransferManager、QBluetoothTransferRequest 和 QBluetoothTransferReply 已被移除,没有替代品。

QBluetoothSocket

QBluetoothSocket::SocketState 和 现在是作用域枚举。枚举项的使用必须在用户代码中进行调整。QBluetoothSocket::SocketError

QML 接口

由于通过 QML 进行套接字编程并不可取,因此删除了 QML 接口。QDeclarativeBluetoothService、QDeclarativeBluetoothSocket 和 QDeclarativeBluetoothDiscoveryModel(QML 中为 BluetoothService、BluetoothSocket 和 BluetoothDiscoveryModel)已被删除,没有替代品。

"错误 "信号

QBluetoothDeviceDiscoveryAgent,QBluetoothLocalDevice,QBluetoothServer,QBluetoothServiceDiscoveryAgent,QBluetoothSocket,QLowEnergyController, 和QLowEnergyService 中的 "error "信号已更名为 "errorOccurred",以消除 "error "信号和 "error "获取器之间的歧义。

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