【发布时间】:2015-06-15 07:23:49
【问题描述】:
我试图了解为什么使用 Qt 重新连接到 BLE 设备会失败。 我的系统是带有内置 BT 适配器的 Ubuntu 14.04,使用 Qt 5.5.0 beta(Qt 5.4.0 也发生过)。
基本上,我要做的是在决定与 BLE 设备断开连接后重新连接到相同或不同的 BLE 设备。请注意,第一个连接很好并且可以正常工作。
执行m_control->connectToDevice(); 后我得到的错误是QLowEnergyController::UnknownError。
连接部分的Stub(基于示例代码):
m_control = new QLowEnergyController(QBluetoothAddress(connection_string), this);
connect(m_control, SIGNAL(serviceDiscovered(QBluetoothUuid)),
this, SLOT(serviceDiscovered(QBluetoothUuid)));
connect(m_control, SIGNAL(discoveryFinished()),
this, SLOT(serviceScanDone()));
connect(m_control, SIGNAL(error(QLowEnergyController::Error)),
this, SLOT(controllerError(QLowEnergyController::Error)));
connect(m_control, SIGNAL(connected()),
this, SLOT(deviceConnected()));
connect(m_control, SIGNAL(disconnected()),
this, SLOT(deviceDisconnected()));
m_control->connectToDevice();
以及断线部分:
if (m_control->state() != QLowEnergyController::UnconnectedState) {
m_control->disconnectFromDevice();
}
delete m_control;
m_control = NULL;
重新连接的唯一方法是重置 BT 适配器或重置远程 BT 设备。软件断开后我也无法扫描设备,所以我猜它仍然与PC配对。
我在这个过程中做错了吗?
【问题讨论】:
标签: c++ qt bluetooth-lowenergy qtcore