Qt for android连接BLE,需求是进入连接ble界面,连接ble。退出连接ble界面ble自动断开。
但很奇怪,退出连接ble界面一次再进入连接ble界面可以连接ble,但多次退出再进入就再也连不上ble了,打印搜索看到无法搜索到要搜索的设备。怀疑是ble没有彻底断开。但查了好多
资料 m_control->disconnectFromDevice();就说明ble与手机就已经断开连接了,请问有谁知道彻底断开ble还需要加入什么代码?我打印了QBluetoothLocalDevice状态,每次退出QBluetoothLocalDevice状态都是关闭状态ClosingState
代码如下 qml用的是
ApplicationWindow在 ApplicationWindow onClosing关闭ble,c++代码如下 if
(m_notificationDesc
.isValid() && m_service
) m_service->writeDescriptor(m_notificationDesc,
QByteArray::fromHex("0000"));
if (m_control)
{
qDebug()<<"---------------------------断开1";
m_control->disconnectFromDevice();
}
qDebug()<<"--------------m_service->state()1;-------------"<<m_service->state();
qDebug()<<"--------------m_control->state()1;-------------"<<m_control->state();
qDeleteAll(m_devices); m_devices.clear();
m_devicesNames.clear();
delete m_service;
m_service = nullptr;