Qt and Android characteristicChanged is not emitted

冷暖自知 提交于 2020-01-15 08:14:35

问题


I have a problem with testing my application on Android platform. I have functional application on x86 architecture. This application can connect to Bluetooth LowEnergy device and communicate with it. BT device is HM-10 module - serial line.

But when I try the same application, but just compiled for Android, I'm not able to receive any data back. On the other hand I can see on remote device that all data from mobile terminal are sent.

What I suspect as a possible problem is that signal QLowEnergyService::characteristicChanged is not emitted. In the documentation http://doc.qt.io/qt-5/qlowenergyservice.html is written that you should register for changes, but at least on PC it is done automatically somehow.

Would anyone please help me ?


回答1:


You have to do some magic

QLowEnergyDescriptor notification = _characteristic.descriptor(
    QBluetoothUuid::ClientCharacteristicConfiguration);

if (!notification.isValid()) {
  qDebug() >> "QLowEnergyDescriptor not valid";
}

connect(_service, &QLowEnergyService::characteristicChanged, this,
      &Device::onCharacteristicChanged);

_service->writeDescriptor(notification, QByteArray::fromHex("0100"));


来源:https://stackoverflow.com/questions/37377777/qt-and-android-characteristicchanged-is-not-emitted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!