QLowEnergyConnectionParameters Class

QLowEnergyConnectionParameters 类用于请求或报告蓝牙 LE 连接参数的更新。更多

Header: #include <QLowEnergyConnectionParameters>
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)

详细说明

连接参数影响主设备和从设备相互同步的频率。一般来说,较低的连接间隔和延迟意味着更快的通信速度,但也意味着更高的能耗。如何权衡这些标准在很大程度上取决于具体的使用情况。

安卓系统只能间接地调整这些参数集。该平台将连接参数分为三类(高优先级、低优先级和平衡优先级)。每个类别意味着minimumInterval(),maximumInterval() 和latency() 的一组预定义值。此外,每个类别的值范围会因不同的 Android 设备而异。Qt XML 使用minimumInterval() 来确定目标类别,具体如下:

minimumInterval()安卓优先级
间隔 < 30连接优先级高
30 <= 间隔 <= 100连接优先级平衡
间隔 > 100连接优先级低

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

另请参阅 QLowEnergyController::requestConnectionUpdateQLowEnergyController::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)

设置连接间隔的范围。实际值由控制器决定。minimummaximum 的单位都是毫秒。如果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)

如果p1p2 的公共状态不相等,则返回true ,否则返回false

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

如果p1p2 的公共状态相等,则返回true ,否则返回false

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