QBluetoothServiceInfo Class

QBluetoothServiceInfo 类允许访问蓝牙服务的属性。更多

Header: #include <QBluetoothServiceInfo>
qmake: QT += bluetooth

公共类型

class Alternative
class Sequence
enum AttributeId { ServiceRecordHandle, ServiceClassIds, ServiceRecordState, ServiceId, ProtocolDescriptorList, …, ServiceProvider }
enum Protocol { UnknownProtocol, L2capProtocol, RfcommProtocol }

公共函数

QBluetoothServiceInfo()
QBluetoothServiceInfo(const QBluetoothServiceInfo &other)
~QBluetoothServiceInfo()
QVariant attribute(quint16 attributeId) const
QList<quint16> attributes() const
bool contains(quint16 attributeId) const
QBluetoothDeviceInfo device() const
bool isComplete() const
bool isRegistered() const
bool isValid() const
QBluetoothServiceInfo::Sequence protocolDescriptor(QBluetoothUuid::ProtocolUuid protocol) const
int protocolServiceMultiplexer() const
bool registerService(const QBluetoothAddress &localAdapter = QBluetoothAddress())
void removeAttribute(quint16 attributeId)
int serverChannel() const
quint8 serviceAvailability() const
QList<QBluetoothUuid> serviceClassUuids() const
QString serviceDescription() const
QString serviceName() const
QString serviceProvider() const
QBluetoothUuid serviceUuid() const
void setAttribute(quint16 attributeId, const QBluetoothServiceInfo::Alternative &value)
void setAttribute(quint16 attributeId, const QBluetoothServiceInfo::Sequence &value)
void setAttribute(quint16 attributeId, const QBluetoothUuid &value)
void setAttribute(quint16 attributeId, const QVariant &value)
void setDevice(const QBluetoothDeviceInfo &device)
void setServiceAvailability(quint8 availability)
void setServiceDescription(const QString &description)
void setServiceName(const QString &name)
void setServiceProvider(const QString &provider)
void setServiceUuid(const QBluetoothUuid &uuid)
QBluetoothServiceInfo::Protocol socketProtocol() const
bool unregisterService()
QBluetoothServiceInfo &operator=(const QBluetoothServiceInfo &other)

详细说明

QBluetoothServiceInfo 提供有关蓝牙设备所提供服务的信息。此外,它还可用于在本地设备上注册新服务。请注意,此类注册只会影响蓝牙 SDP 条目。任何监听传入连接的服务器(如 RFCOMM 服务器)都必须在调用registerService() 之前启动。取消注册必须以相反的顺序进行。

QBluetoothServiceInfo 不是传统意义上的值类型。同一服务信息对象的所有副本共享相同的数据,因为它们在更改时不会分离。这确保了两个副本可以(重新)注册相同的蓝牙服务。

在 iOS 平台上,该类不能使用,因为该平台没有公开允许访问 QBluetoothServiceInfo 相关功能的 API。

成员类型文档

enum QBluetoothServiceInfo::AttributeId

蓝牙服务属性。有关这些属性的详细说明,请查阅蓝牙核心规范。

常数描述
QBluetoothServiceInfo::ServiceRecordHandle0x0000指定可从中检索属性的服务记录。
QBluetoothServiceInfo::ServiceClassIds0x0001服务符合的服务类别的 UUID。(QBluetoothUuid::ServiceClassUuid) 中定义了最常见的服务类别。
QBluetoothServiceInfo::ServiceRecordState0x0002当添加、删除或修改任何其他服务属性时,属性会发生变化。
QBluetoothServiceInfo::ServiceId0x0003唯一标识服务的 UUID。
QBluetoothServiceInfo::ProtocolDescriptorList0x0004服务使用的协议列表。最常见的协议 UUID 定义如下QBluetoothUuid::ProtocolUuid
QBluetoothServiceInfo::BrowseGroupList0x0005服务所在的浏览组列表。
QBluetoothServiceInfo::LanguageBaseAttributeIdList0x0006支持人类可读属性的语言基础属性 ID 列表。
QBluetoothServiceInfo::ServiceInfoTimeToLive0x0007服务记录预计保持有效和不变的秒数。
QBluetoothServiceInfo::ServiceAvailability0x0008表示服务可用性的值。
QBluetoothServiceInfo::BluetoothProfileDescriptorList0x0009服务符合的配置文件列表。
QBluetoothServiceInfo::DocumentationUrl0x000A指向服务文档的 URL。
QBluetoothServiceInfo::ClientExecutableUrl0x000B指向可用于使用服务的应用程序位置的 URL。
QBluetoothServiceInfo::IconUrl0x000C指向代表服务图标位置的 URL。
QBluetoothServiceInfo::AdditionalProtocolDescriptorList0x000D服务使用的其他协议。该属性扩展了ProtocolDescriptorList
QBluetoothServiceInfo::PrimaryLanguageBase0x0100主要语言文本描述符的基本索引。
QBluetoothServiceInfo::ServiceNamePrimaryLanguageBase + 0x0000蓝牙服务的主要语言名称。
QBluetoothServiceInfo::ServiceDescriptionPrimaryLanguageBase + 0x0001蓝牙服务的主要语言描述。
QBluetoothServiceInfo::ServiceProviderPrimaryLanguageBase + 0x0002提供主要语言蓝牙服务的公司/实体名称。

注意: 在 Windows 上,创建服务时,ServiceClassIds 和 ProtocolDescriptorList 会自动设置为默认值。在此平台上,手动设置这些属性的值将不起作用,并可能导致意想不到的结果。

enum QBluetoothServiceInfo::Protocol

该枚举描述了服务使用的套接字协议。

常量说明
QBluetoothServiceInfo::UnknownProtocol0服务使用未知套接字协议。
QBluetoothServiceInfo::L2capProtocol1服务使用 L2CAP 套接字协议。Android 不支持该协议用于直接套接字连接。
QBluetoothServiceInfo::RfcommProtocol2该服务使用 RFCOMM 套接字协议。

成员函数文档

QBluetoothServiceInfo::QBluetoothServiceInfo()

构建一个新的无效 QBluetoothServiceInfo;

QBluetoothServiceInfo::QBluetoothServiceInfo(const QBluetoothServiceInfo &other)

构建一个新的 QBluetoothServiceInfo,它是other 的副本。

这两个副本继续共享相同的底层数据,写入时不会分离。

[noexcept] QBluetoothServiceInfo::~QBluetoothServiceInfo()

销毁QBluetoothServiceInfo 对象。

QVariant QBluetoothServiceInfo::attribute(quint16 attributeId) const

返回属性attributeId 的值。

另请参阅 setAttribute() 。

QList<quint16> QBluetoothServiceInfo::attributes() const

返回QBluetoothServiceInfo 对象的所有属性 id 列表。

bool QBluetoothServiceInfo::contains(quint16 attributeId) const

如果QBluetoothServiceInfo 对象包含属性attributeId ,则返回 true,否则返回 false。

QBluetoothDeviceInfo QBluetoothServiceInfo::device() const

返回提供此服务的蓝牙设备的地址。

另请参阅 setDevice()。

bool QBluetoothServiceInfo::isComplete() const

如果QBluetoothServiceInfo 对象被认为是完整的,则返回 true,否则返回 false。

完整的QBluetoothServiceInfo 对象包含一个ProtocolDescriptorList 属性。

bool QBluetoothServiceInfo::isRegistered() const

如果服务信息已在平台的服务发现协议 (SDP) 实现中注册,则返回 true,否则返回 false。

bool QBluetoothServiceInfo::isValid() const

如果QBluetoothServiceInfo 对象有效,则返回 true,否则返回 false。

无效的QBluetoothServiceInfo 对象将没有属性。

QBluetoothServiceInfo::Sequence QBluetoothServiceInfo::protocolDescriptor(QBluetoothUuid::ProtocolUuid protocol) const

QBluetoothServiceInfo::Sequence 的形式返回协议参数,用于协议protocol

如果不支持protocol ,则返回空QBluetoothServiceInfo::Sequence

int QBluetoothServiceInfo::protocolServiceMultiplexer() const

这是一个便利函数。返回支持 L2CAP 协议的服务的协议/服务多路复用器,否则返回-1。

该函数等同于从QBluetoothServiceInfo::attribute(QBluetoothServiceInfo::ProtocolDescriptorList) 返回的QBluetoothServiceInfo::Sequence 中提取信息。

bool QBluetoothServiceInfo::registerService(const QBluetoothAddress &localAdapter = QBluetoothAddress())

在平台的服务发现协议(SDP)实现中注册此服务,使其他设备在执行服务发现时可以找到它。如果服务注册成功,则返回 true,否则返回 false。一旦注册成功,就不能更改记录。服务必须取消注册,并在更改后重新注册。

localAdapter 参数决定服务应注册的本地蓝牙适配器。如果localAdapternull ,则将使用默认蓝牙适配器。如果此服务信息对象已通过本地适配器注册,而调用此函数时使用了不同的本地适配器,则会删除之前的注册,并使用新的适配器重新注册服务。

void QBluetoothServiceInfo::removeAttribute(quint16 attributeId)

删除QBluetoothServiceInfo 对象中的属性attributeId

如果服务信息已在平台 SDP 数据库中注册,则在再次调用registerService() 之前不会更新数据库条目。

int QBluetoothServiceInfo::serverChannel() const

这是一个便利函数。返回支持 RFCOMM 协议的服务的服务器通道,否则返回-1。

该函数等同于从QBluetoothServiceInfo::Sequence 中提取QBluetoothServiceInfo::attribute (QBluetootherServiceInfo::ProtocolDescriptorList)返回的信息。

quint8 QBluetoothServiceInfo::serviceAvailability() const

这是一个便利函数。它等同于调用 attribute(QBluetoothServiceInfo::ServiceAvailability).toUInt() 函数。

返回服务的可用性。

另请参阅 setServiceAvailability() 和attribute()。

QList<QBluetoothUuid> QBluetoothServiceInfo::serviceClassUuids() const

返回描述此服务所符合的服务类别的 UUID 列表。

这是一个便利函数。它等同于调用 attribute(QBluetoothServiceInfo::ServiceClassIds).value<QBluetoothServiceInfo::Sequence>() 并随后遍历其QBluetoothUuid 条目。

另请参阅 attribute().

QString QBluetoothServiceInfo::serviceDescription() const

这是一个便利函数。它等同于调用 attribute(QBluetoothServiceInfo::ServiceDescription).toString().

返回主要语言的服务描述。

另请参阅 setServiceDescription() 和attribute()。

QString QBluetoothServiceInfo::serviceName() const

这是一个便利函数。它等同于调用 attribute(QBluetoothServiceInfo::ServiceName).toString().

返回主要语言的服务名称。

另请参阅 setServiceName() 和attribute()。

QString QBluetoothServiceInfo::serviceProvider() const

这是一个便利函数。它等同于调用 attribute(QBluetoothServiceInfo::ServiceProvider).toString().

返回服务提供者的主要语言。

另请参阅 setServiceProvider() 和attribute()。

QBluetoothUuid QBluetoothServiceInfo::serviceUuid() const

这是一个方便的函数。它等同于调用 attribute(QBluetoothServiceInfo::ServiceId).value<QBluetoothUuid>()。

返回服务的自定义 UUID。该 UUID 可能为空。基于蓝牙 SIG 标准的 UUID 应通过serviceClassUuids() 获取。

另请参阅 setServiceUuid() 和attribute()。

void QBluetoothServiceInfo::setAttribute(quint16 attributeId, const QBluetoothServiceInfo::Alternative &value)

这是一个便利函数。

attributeId 标识的属性设置为value

如果服务信息已在平台的 SDP 数据库中注册,则在再次调用registerService() 之前不会更新数据库条目。

另请参阅 attribute()。

void QBluetoothServiceInfo::setAttribute(quint16 attributeId, const QBluetoothServiceInfo::Sequence &value)

这是一个便利函数。

attributeId 标识的属性设置为value

如果服务信息已在平台的 SDP 数据库中注册,则在再次调用registerService() 之前不会更新数据库条目。

void QBluetoothServiceInfo::setAttribute(quint16 attributeId, const QBluetoothUuid &value)

这是一个便利函数。

attributeId 标识的属性设置为value

如果服务信息已在平台的 SDP 数据库中注册,则在再次调用registerService() 之前不会更新数据库条目。

void QBluetoothServiceInfo::setAttribute(quint16 attributeId, const QVariant &value)

attributeId 标识的属性设置为value

如果服务信息已在平台的 SDP 数据库中注册,则数据库条目将不会更新,直到再次调用registerService() 时才会更新。

注意: 如果属性预期值是字节编码值(如蓝牙 HID 服务),则应将其设置为QByteArray

另请参阅 isRegistered() 和registerService()。

void QBluetoothServiceInfo::setDevice(const QBluetoothDeviceInfo &device)

将提供此服务的蓝牙设备设置为device

另请参阅 device() 。

void QBluetoothServiceInfo::setServiceAvailability(quint8 availability)

这是一个便利函数。它等同于调用setAttribute(QBluetoothServiceInfo::ServiceAvailability, availability)。

将服务的可用性设置为availability

另请参阅 serviceAvailability() 和setAttribute()。

void QBluetoothServiceInfo::setServiceDescription(const QString &description)

这是一个便利函数。它等同于调用setAttribute(QBluetoothServiceInfo::ServiceDescription, description)。

将主要语言的服务描述设置为description

另请参阅 serviceDescription() 和setAttribute()。

void QBluetoothServiceInfo::setServiceName(const QString &name)

这是一个便利函数。它等同于调用setAttribute(QBluetoothServiceInfo::ServiceName, name)。

将主要语言的服务名称设置为name

另请参阅 serviceName() 和setAttribute()。

void QBluetoothServiceInfo::setServiceProvider(const QString &provider)

这是一个便利函数。它等同于调用setAttribute(QBluetoothServiceInfo::ServiceProvider, provider)。

将主要语言的服务提供者设置为provider

另请参阅 serviceProvider() 和setAttribute()。

void QBluetoothServiceInfo::setServiceUuid(const QBluetoothUuid &uuid)

这是一个便利函数。它等同于调用setAttribute(QBluetoothServiceInfo::ServiceId, uuid)。

将自定义服务 UUID 设为uuid 。此函数不能用于设置标准化服务 UUID。

另请参阅 serviceUuid() 和setAttribute()。

QBluetoothServiceInfo::Protocol QBluetoothServiceInfo::socketProtocol() const

返回QBluetoothServiceInfo 对象使用的协议。

bool QBluetoothServiceInfo::unregisterService()

在平台的服务发现协议 (SDP) 实现中取消注册该服务。此后,其他设备将无法通过服务发现找到该服务。

如果服务成功取消注册,则返回 true,否则返回 false。

QBluetoothServiceInfo &QBluetoothServiceInfo::operator=(const QBluetoothServiceInfo &other)

复制other 并将其分配给QBluetoothServiceInfo 对象。这两个副本继续共享相同的服务和注册详细信息。

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