本页内容

QLowEnergyConnectionParameters Class

QLowEnergyConnectionParameters 类用于请求或报告蓝牙低功耗(Bluetooth LE)连接参数的更新。更多内容...

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

公共函数

QLowEnergyConnectionParameters()
QLowEnergyConnectionParameters(const QLowEnergyConnectionParameters &other)
~QLowEnergyConnectionParameters()
int latency() const
double maximumInterval() const
double minimumInterval() const
void setIntervalRange(double minimum, double maximum)
void setLatency(int latency)
void setSupervisionTimeout(int timeout)
int supervisionTimeout() const
void swap(QLowEnergyConnectionParameters &other)
QLowEnergyConnectionParameters &operator=(const QLowEnergyConnectionParameters &other)
bool operator!=(const QLowEnergyConnectionParameters &p1, const QLowEnergyConnectionParameters &p2)
bool operator==(const QLowEnergyConnectionParameters &p1, const QLowEnergyConnectionParameters &p2)

详细说明

连接参数影响主设备和从设备之间同步的频率。通常,连接间隔和延迟越低,通信速度越快,但功耗也会越高。如何权衡这些标准,在很大程度上取决于具体的使用场景。

Android仅允许间接调整这组参数。该平台将连接参数分为三类(高、低及平衡优先级)。每类都对应minimumInterval()、maximumInterval()和latency()的预定义值集。此外,不同Android设备间,各类别的数值范围可能存在差异。 Qt 通过minimumInterval() 函数按以下方式确定目标类别:

minimumInterval()Android 优先级
间隔 < 30CONNECTION_PRIORITY_HIGH
30 <= 间隔 <= 100CONNECTION_PRIORITY_BALANCED
间隔 > 100CONNECTION_PRIORITY_LOW_POWER

supervisionTimeout() 在 Android 系统上无法更改,因此将被忽略。

另请参阅 QLowEnergyController::requestConnectionUpdate 和QLowEnergyController::connectionUpdated 。

成员函数文档

QLowEnergyConnectionParameters::QLowEnergyConnectionParameters()

创建该类的一个新对象。所有值均初始化为有效的默认值。

QLowEnergyConnectionParameters::QLowEnergyConnectionParameters(const QLowEnergyConnectionParameters &other)

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

[noexcept] QLowEnergyConnectionParameters::~QLowEnergyConnectionParameters()

销毁该对象。

int QLowEnergyConnectionParameters::latency() const

返回连接的从节点延迟。

另请参阅 setLatency()。

double QLowEnergyConnectionParameters::maximumInterval() const

返回最大连接间隔(单位为毫秒)。默认值为 4000。

注意:如果 该对象是通过 `QLowEnergyController::connectionUpdated()` 发出的,则此值与 `minimumInterval()` 相同,并指代实际的连接间隔。

另请参阅 setIntervalRange()。

double QLowEnergyConnectionParameters::minimumInterval() const

返回最小连接间隔(单位为毫秒)。默认值为 7.5。

注意:如果 该对象是通过QLowEnergyController::connectionUpdated() 生成的,则此值与maximumInterval() 返回的值相同,且指代实际的连接间隔。

另请参阅 setIntervalRange()。

void QLowEnergyConnectionParameters::setIntervalRange(double minimum, double maximum)

设置连接间隔应处于的范围。具体数值将由控制器决定。minimum 和maximum 均以毫秒为单位。如果maximum 小于minimum ,则将其设置为minimum 的值。连接间隔的最小值为7.5毫秒,最大值为4000毫秒。

另请参阅 minimumInterval() 和maximumInterval()。

void QLowEnergyConnectionParameters::setLatency(int latency)

将连接的从设备延迟(即从设备允许忽略的连接事件数量)设置为latency 。最小值为0,最大值为499。

另请参阅 latency()。

void QLowEnergyConnectionParameters::setSupervisionTimeout(int timeout)

将链路监视超时设置为timeout 毫秒。该值受以下限制:必须在[100,32000]范围内,且必须大于(1 +latency()) * 2 *maximumInterval()。

在 Android 系统上,此超时时间不可调整,因此会被忽略。

另请参阅 supervisionTimeout()。

int QLowEnergyConnectionParameters::supervisionTimeout() const

返回连接的链路监视超时时间(单位为毫秒)。

另请参阅 setSupervisionTimeout()。

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

将此对象与other 互换。

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

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

相关的非成员

bool operator!=(const QLowEnergyConnectionParameters &p1, const QLowEnergyConnectionParameters &p2)

如果p1 和p2 的公共状态不相同,则返回true ;否则返回false 。

bool operator==(const QLowEnergyConnectionParameters &p1, const QLowEnergyConnectionParameters &p2)

如果 `p1 ` 和 `p2 ` 的公共状态相等,则返回 `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.