diff options
author | Oliver Wolff <oliver.wolff@qt.io> | 2019-06-07 09:05:36 +0200 |
---|---|---|
committer | Oliver Wolff <oliver.wolff@qt.io> | 2019-06-24 12:09:46 +0200 |
commit | d755f7ab67a1f5b345caf09b1fc798d3c6e0ca34 (patch) | |
tree | 0c7e8cddf98bb62ebd350b4a593af38cacbf3aa2 /src/bluetooth/qlowenergycontroller_winrt_new.cpp | |
parent | 0a49c93037e5f819f60486af318b6708e3b2b4aa (diff) |
winrt: Avoid threading issues when handling characteristic changes
As callbacks do not necessarily happen on Qt's main thread, it is
possible that we access the service list while it is being changed if we
access it from the callback directly. Doing this can cause application
crashes. Thus we hand back the information about a changed characteristic
to the main thread via signal/slot and handle it from the main thread.
With QLowEnergyControllerPrivateWinRTNew having the Q_OBJECT macro, we
can no longer use forward declares for the GATT classes as moc chokes on
these. Thus an include is used.
Fixes: QTBUG-75907
Change-Id: I063794eecf904921ff55fab76a5bdde3a9aebf44
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/bluetooth/qlowenergycontroller_winrt_new.cpp')
-rw-r--r-- | src/bluetooth/qlowenergycontroller_winrt_new.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/bluetooth/qlowenergycontroller_winrt_new.cpp b/src/bluetooth/qlowenergycontroller_winrt_new.cpp index bb9894ff..3f1b04f2 100644 --- a/src/bluetooth/qlowenergycontroller_winrt_new.cpp +++ b/src/bluetooth/qlowenergycontroller_winrt_new.cpp @@ -435,6 +435,9 @@ QLowEnergyControllerPrivateWinRTNew::QLowEnergyControllerPrivateWinRTNew() : QLowEnergyControllerPrivate() { registerQLowEnergyControllerMetaType(); + connect(this, &QLowEnergyControllerPrivateWinRTNew::characteristicChanged, + this, &QLowEnergyControllerPrivateWinRTNew::handleCharacteristicChanged, + Qt::QueuedConnection); } QLowEnergyControllerPrivateWinRTNew::~QLowEnergyControllerPrivateWinRTNew() @@ -613,7 +616,7 @@ HRESULT QLowEnergyControllerPrivateWinRTNew::onValueChange(IGattCharacteristic * ComPtr<IBuffer> buffer; hr = args->get_CharacteristicValue(&buffer); RETURN_IF_FAILED("Could not obtain characteristic's value", return S_OK) - characteristicChanged(handle, byteArrayFromBuffer(buffer)); + emit characteristicChanged(handle, byteArrayFromBuffer(buffer)); return S_OK; } @@ -1487,9 +1490,10 @@ void QLowEnergyControllerPrivateWinRTNew::addToGenericAttributeList(const QLowEn Q_UNIMPLEMENTED(); } -void QLowEnergyControllerPrivateWinRTNew::characteristicChanged( +void QLowEnergyControllerPrivateWinRTNew::handleCharacteristicChanged( quint16 charHandle, const QByteArray &data) { + qCDebug(QT_BT_WINRT) << __FUNCTION__ << charHandle << data; QSharedPointer<QLowEnergyServicePrivate> service = serviceForHandle(charHandle); if (service.isNull()) |