简体   繁体   中英

Invisible BLE device when Qt scanning

I'm new on Bluetooth Low Energy (BLE) device development and I have to develop an HMI (on Windows 10) which is able to communicate with the BLE device.

For this purpose, I choose to develop my SW with Qt v5.14.2 which includes API for Bluetooth communication.

I'm in the first step, which is scanning devices around me. For this test, I have some standard Bluetooth devices around and also a BLE dev kit (Nordic nRF52) that advertise permanently.

My problem is that: when I run my code, I can find standard Bluetooth devices around but not the BLE device.. (With another app I can find it all..).

Here is my code: 1) My constructor which initialize the Bluetooth com and start it:

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) the slot addDevice() which extract devices found:

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;
    //}
}

Can you help me to find out the solution, please?

Problem resolved. I just change my compiler from minGW to MSVC and it works fine, The precise reason is still unknown for me. but the solution is here.

Some info for future visitors:

"Win32 backend has been removed. There will not be a working Bluetooth backend when Qt is built with mingw."

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM