Skip to content

Commit

Permalink
Prevent crash on MSVC 32-bit build
Browse files Browse the repository at this point in the history
The WinRT API might show `80040154 Class not registered` when running
`getRadioFromAdapterId()` and returns a null Radio object. I guess it's
caused by the platform configuration of the WinRT API set to `Any CPU`,
but I'm running the 32-bit build on a 64-bit machine. In this case, the
Bluetooth is disabled. However, I don't know if this build is working on
a native 32-bit machine.
  • Loading branch information
wh201906 committed Apr 14, 2024
1 parent 6fffcb0 commit 64b8154
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/winrtbluetooth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <winrt/Windows.Devices.Radios.h>

#include <QCoreApplication>
#include <QDebug>
#include <QElapsedTimer>

using namespace winrt::Windows::Foundation;
Expand Down Expand Up @@ -76,8 +77,13 @@ QList<QBluetoothHostInfo> WinRTBluetooth::allLocalDevices(bool PoweredOnOnly)
for(const auto &devInfo : deviceInfoCollection)
{
BluetoothAdapter adapter(nullptr);
Radio radio(nullptr);
const bool res = await(BluetoothAdapter::FromIdAsync(devInfo.Id()), adapter);
if(res && adapter && (!PoweredOnOnly || getRadioFromAdapterId(devInfo.Id()).State() == RadioState::On))
if(!res || !adapter)
{
continue;
}
if(!PoweredOnOnly || ((radio = getRadioFromAdapterId(devInfo.Id())) && radio.State() == RadioState::On))
{
QBluetoothHostInfo info;
info.setName(QString::fromStdString(winrt::to_string(devInfo.Name())));
Expand Down

0 comments on commit 64b8154

Please sign in to comment.