diff options
author | Oliver Wolff <oliver.wolff@qt.io> | 2016-07-18 12:55:20 +0200 |
---|---|---|
committer | Oliver Wolff <oliver.wolff@qt.io> | 2016-07-26 12:34:14 +0000 |
commit | f5b90dd2e93a950f9d8d2b543022182761aefd67 (patch) | |
tree | 8edc0c6caf09b39fe2e35be97b835f9a07db7be9 | |
parent | 168a79fd266e4ae9de5b312446904a303e7442a4 (diff) |
Register connectionStatus callback in Xaml thread
Change-Id: I06777c75c20f662d3dff897f65947321eb79d5a2
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
-rw-r--r-- | src/bluetooth/qlowenergycontroller_winrt.cpp | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/bluetooth/qlowenergycontroller_winrt.cpp b/src/bluetooth/qlowenergycontroller_winrt.cpp index f25b5060..1561f560 100644 --- a/src/bluetooth/qlowenergycontroller_winrt.cpp +++ b/src/bluetooth/qlowenergycontroller_winrt.cpp @@ -310,19 +310,23 @@ void QLowEnergyControllerPrivate::connectToDevice() BluetoothConnectionStatus status; hr = mDevice->get_ConnectionStatus(&status); Q_ASSERT_SUCCEEDED(hr); - hr = mDevice->add_ConnectionStatusChanged(Callback<StatusHandler>([this, q](IBluetoothLEDevice *dev, IInspectable *){ - BluetoothConnectionStatus status; - dev->get_ConnectionStatus(&status); - if (status == BluetoothConnectionStatus::BluetoothConnectionStatus_Connected) { - setState(QLowEnergyController::ConnectedState); - emit q->connected(); - } else if (status == BluetoothConnectionStatus::BluetoothConnectionStatus_Disconnected) { - setState(QLowEnergyController::UnconnectedState); - emit q->disconnected(); - } + hr = QEventDispatcherWinRT::runOnXamlThread([this, q]() { + HRESULT hr; + hr = mDevice->add_ConnectionStatusChanged(Callback<StatusHandler>([this, q](IBluetoothLEDevice *dev, IInspectable *) { + BluetoothConnectionStatus status; + dev->get_ConnectionStatus(&status); + if (status == BluetoothConnectionStatus::BluetoothConnectionStatus_Connected) { + setState(QLowEnergyController::ConnectedState); + emit q->connected(); + } else if (status == BluetoothConnectionStatus::BluetoothConnectionStatus_Disconnected) { + setState(QLowEnergyController::UnconnectedState); + emit q->disconnected(); + } + return S_OK; + }).Get(), &mStatusChangedToken); + Q_ASSERT_SUCCEEDED(hr); return S_OK; - }).Get(), &mStatusChangedToken); - Q_ASSERT_SUCCEEDED(hr); + }); if (status == BluetoothConnectionStatus::BluetoothConnectionStatus_Connected) { setState(QLowEnergyController::ConnectedState); |