1

I'm trying to use Qt Bluetooth on Qt 5.8 and WinRT. I understand it's something that MUST go wrong one way or another but I'd like to avoid mixing Qt and native Windows APIs. I'm pretty sure I'm missing something super obvious right now.

const QLowEnergyCharacteristic characteristic = m_service->characteristic(
                QBluetoothUuid(QBluetoothUuid::GlucoseMeasurement));

if (!characteristic.isValid()) {
    break;
}

m_notificationDesc = characteristic.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
if (m_notificationDesc.isValid()) {
    m_service->writeDescriptor(m_notificationDesc, enable_notification);
}

Where enable_notification is QByteArray::fromHex("0100");.

After calling writeDescriptor, I get QLowEnergyService::DescriptorWriteError and an instant disconnect. Any ideas?

demonplus
  • 5,613
  • 12
  • 49
  • 68
pisarz1958
  • 21
  • 1
  • Have you checked if `QLowEnergyCharacteristic::properties()` has `QLowEnergyCharacteristic::Notify` flag? Also, please try to read the descriptor before you write it....just in case it fixes the problem...(experienced that in the past). – jpo38 Nov 24 '16 at 20:44
  • Also, did you try to connect and enable CCCD using a generic BLE tool (downloaded from any store)? Just to be sure your device's GlucoseMeasurement's CCCD is writtable. – jpo38 Nov 24 '16 at 20:45
  • Two other things you may want to check: 1- have you received `QLowEnergyService::ServiceDiscovered` before you tried to call `writeDescriptor`? 2- are you calling `writeDescriptor` from the main thread? – jpo38 Nov 24 '16 at 20:54
  • `QLowEnergyCharacteristic::properties()` does have the notify flag. I'm calling writeDescriptor just after receiving ServiceDiscovered. It is called from the main thread. This time I also got this in the output: `QObject::connect: Cannot queue arguments of type 'QLowEnergyDescriptor' (Make sure 'QLowEnergyDescriptor' is registered using qRegisterMetaType().)` When both readDescriptor and writeDescriptor were called (it might be a bug in Qt). – pisarz1958 Nov 25 '16 at 11:09
  • Wierd, `writeDescriptor` works fine for me. Can you test on an Android device (that's what I use)? – jpo38 Nov 25 '16 at 12:39
  • Turns out both the random disconnects and not working callbacks are bugs in Qt, first one is solved in recent snapshots, second one - I guess I'm going to report that. Thanks. – pisarz1958 Nov 29 '16 at 17:57
  • Strange, I'm using Qt 5.7 on Android and never saw those issues. Are they WinRT specific? – jpo38 Nov 29 '16 at 18:59
  • WinRT specific. Kinda expected, since Bluetooth support there is still experimental. I built the app against Android and it just worked as it was supposed to. – pisarz1958 Nov 29 '16 at 19:22

0 Answers0