• 2624阅读
  • 3回复

[提问]Qt for android  BLE问题请教 [复制链接]

上一主题 下一主题
离线nikonice
 

只看楼主 倒序阅读 楼主  发表于: 2019-06-03
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;

只看该作者 1楼 发表于: 2019-10-09
Re:Qt for android  BLE问题请教
你试试每次断开连接后,再 delete m_control; m_control = nullptr;  下次需要连接时在new用出来试试。
离线buyi

只看该作者 2楼 发表于: 2020-03-01
这么久了,问题解决没有
本帖提到的人: @nikonice
三人行,必有我师。
离线nikonice

只看该作者 3楼 发表于: 2020-03-24
  if (m_notificationDesc.isValid() && m_service) {
        m_service->writeDescriptor(m_notificationDesc, QByteArray::fromHex("0000"));
    } else {
        m_control->disconnectFromDevice();
        delete m_service;
        m_service = 0;
    }
即可
快速回复
限100 字节
 
上一个 下一个