查看完整版本: [-- Qt for android  BLE问题请教 --]

QTCN开发网 -> Qt移动平台开发 -> Qt for android  BLE问题请教 [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

nikonice 2019-06-03 10:14

Qt for android  BLE问题请教

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;

大千世界mcq 2019-10-09 10:41
你试试每次断开连接后,再 delete m_control; m_control = nullptr;  下次需要连接时在new用出来试试。

buyi 2020-03-01 13:02
这么久了,问题解决没有

nikonice 2020-03-24 13:49
  if (m_notificationDesc.isValid() && m_service) {
        m_service->writeDescriptor(m_notificationDesc, QByteArray::fromHex("0000"));
    } else {
        m_control->disconnectFromDevice();
        delete m_service;
        m_service = 0;
    }
即可


查看完整版本: [-- Qt for android  BLE问题请教 --] [-- top --]



Powered by phpwind v8.7 Code ©2003-2011 phpwind
Gzip disabled