本页内容

QLowEnergyServiceData Class

QLowEnergyServiceData 类用于配置 GATT 服务数据。更多内容...

头文件: #include <QLowEnergyServiceData>
CMake: find_package(Qt6 REQUIRED COMPONENTS Bluetooth)
target_link_libraries(mytarget PRIVATE Qt6::Bluetooth)
qmake: QT += bluetooth

公共类型

enum ServiceType { ServiceTypePrimary, ServiceTypeSecondary }

公共函数

QLowEnergyServiceData()
QLowEnergyServiceData(const QLowEnergyServiceData &other)
~QLowEnergyServiceData()
void addCharacteristic(const QLowEnergyCharacteristicData &characteristic)
void addIncludedService(QLowEnergyService *service)
QList<QLowEnergyCharacteristicData> characteristics() const
QList<QLowEnergyService *> includedServices() const
bool isValid() const
void setCharacteristics(const QList<QLowEnergyCharacteristicData> &characteristics)
void setIncludedServices(const QList<QLowEnergyService *> &services)
void setType(QLowEnergyServiceData::ServiceType type)
void setUuid(const QBluetoothUuid &uuid)
void swap(QLowEnergyServiceData &other)
QLowEnergyServiceData::ServiceType type() const
QBluetoothUuid uuid() const
QLowEnergyServiceData &operator=(const QLowEnergyServiceData &other)
bool operator!=(const QLowEnergyServiceData &a, const QLowEnergyServiceData &b)
bool operator==(const QLowEnergyServiceData &a, const QLowEnergyServiceData &b)

详细描述

该类的对象提供了一项服务,可通过QLowEnergyController::addService()将其添加到 GATT 服务器中。

成员类型文档

enum QLowEnergyServiceData::ServiceType

《关贸总协定》中的服务类型。

常量值描述
QLowEnergyServiceData::ServiceTypePrimary0x2800该服务为一级服务。
QLowEnergyServiceData::ServiceTypeSecondary0x2801该服务是二级服务。二级服务被其他服务包含在内,以实现某些更高级的功能。

成员函数文档

QLowEnergyServiceData::QLowEnergyServiceData()

创建该类的一个新的无效对象。

QLowEnergyServiceData::QLowEnergyServiceData(const QLowEnergyServiceData &other)

创建该类的一个新对象,该对象是other 的副本。

[noexcept] QLowEnergyServiceData::~QLowEnergyServiceData()

销毁该对象。

void QLowEnergyServiceData::addCharacteristic(const QLowEnergyCharacteristicData &characteristic)

如果characteristic 有效,则将其添加到特征列表中。

另请参阅 setCharacteristics()。

void QLowEnergyServiceData::addIncludedService(QLowEnergyService *service)

将service 添加到已包含的服务列表中。service 对象必须是从调用QLowEnergyController::addService 返回的。此要求可防止循环包含(蓝牙规范禁止此类操作),同时有助于支持包含多个同类型服务的使用场景。

另请参阅 setIncludedServices()。

QList<QLowEnergyCharacteristicData> QLowEnergyServiceData::characteristics() const

返回特征列表。

另请参阅 setCharacteristics()。

QList<QLowEnergyService *> QLowEnergyServiceData::includedServices() const

返回已包含的服务列表。

另请参阅 setIncludedServices()。

bool QLowEnergyServiceData::isValid() const

如果该服务具有非空的 UUID,则返回true 。

void QLowEnergyServiceData::setCharacteristics(const QList<QLowEnergyCharacteristicData> &characteristics)

将特征列表设置为characteristics 。仅考虑有效的特征。

另请参阅 characteristics() 和addCharacteristic()。

void QLowEnergyServiceData::setIncludedServices(const QList<QLowEnergyService *> &services)

将包含的服务列表设置为services 。该列表中的所有对象都必须是从调用QLowEnergyController::addService 返回的。

另请参阅 includedServices() 和addIncludedService()。

void QLowEnergyServiceData::setType(QLowEnergyServiceData::ServiceType type)

将此服务的类型设置为type 。

另请参阅 type()。

void QLowEnergyServiceData::setUuid(const QBluetoothUuid &uuid)

将此服务的 UUID 设置为uuid 。

另请参阅 uuid()。

[noexcept] void QLowEnergyServiceData::swap(QLowEnergyServiceData &other)

将此对象与other 互换。

QLowEnergyServiceData::ServiceType QLowEnergyServiceData::type() const

返回此服务的类型。

另请参阅 setType()。

QBluetoothUuid QLowEnergyServiceData::uuid() const

返回该服务的 UUID。

另请参阅 setUuid()。

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

将该对象复制为other 的副本,并返回该对象的新值。

相关的非成员

bool operator!=(const QLowEnergyServiceData &a, const QLowEnergyServiceData &b)

如果 `a ` 和 `b ` 的公共状态不一致,则返回 `true `;否则返回 `false`。

bool operator==(const QLowEnergyServiceData &a, const QLowEnergyServiceData &b)

如果a 和b 的公共状态相等,则返回 `true `;否则返回 `false`。

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