Qt扫描时不可见的BLE设备

Invisible BLE device when Qt scanning

我是蓝牙低功耗 (BLE) 设备开发的新手,我必须开发一个能够与 BLE 设备通信的 HMI(在 Windows 10 上)。

为此,我选择使用 Qt v5.14.2 开发我的软件,其中包括 API 用于蓝牙通信。

我正在第一步,扫描我周围的设备。对于这个测试,我有一些标准的蓝牙设备,还有一个 BLE 开发套件 (Nordic nRF52),它可以永久地做广告。

我的问题是:当我 运行 我的代码时,我可以找到周围的标准蓝牙设备,但找不到 BLE 设备..(使用另一个应用程序我可以找到所有设备..)。

这是我的代码: 1) 我的构造函数初始化蓝牙 com 并启动它:

CemBluetooth::CemBluetooth(QObject *parent) : QObject(parent)
{
    discoveryAgent = new QBluetoothDeviceDiscoveryAgent();
    discoveryAgent -> setLowEnergyDiscoveryTimeout(10000); // in ms

    connect(discoveryAgent, SIGNAL(deviceDiscovered(const QBluetoothDeviceInfo&)), this, SLOT(addDevice(const QBluetoothDeviceInfo&)));
    connect(discoveryAgent, SIGNAL(finished()), this, SLOT(f_ctrl_bl_scanBlDevicesFinished()));

    discoveryAgent->start(QBluetoothDeviceDiscoveryAgent::LowEnergyMethod);
}

2) 找到提取设备的插槽 addDevice():

void CemBluetooth::addDevice(const QBluetoothDeviceInfo& device)
{
    std::cout << "Device discovered: ";
    //if (device.coreConfigurations() & QBluetoothDeviceInfo::LowEnergyCoreConfiguration) // i shunt this condition for the moment, in order to detect all device.
    //{
        QString name1 = device.name();
        std::cout << name1.toStdString() << std::endl;
    //}
}

你能帮我找出解决办法吗?

问题已解决!我只是将我的编译器从 minGW 更改为 MSVC,它工作正常。我仍然不知道确切的原因,但解决方案就在这里。

给未来访客的一些信息:

“Win32 后端已被删除。当使用 mingw 构建 Qt 时,蓝牙后端将无法正常工作。”

Link: https://doc-snapshots.qt.io/qt6-dev/qtbluetooth-changes-qt6.html