From f5b90dd2e93a950f9d8d2b543022182761aefd67 Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Mon, 18 Jul 2016 12:55:20 +0200 Subject: Register connectionStatus callback in Xaml thread Change-Id: I06777c75c20f662d3dff897f65947321eb79d5a2 Reviewed-by: Alex Blasche --- src/bluetooth/qlowenergycontroller_winrt.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'src/bluetooth/qlowenergycontroller_winrt.cpp') 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([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([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); -- cgit v1.2.3