Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

What is the purpose of QBluetoothDeviceDiscoveryAgent::setLowEnergyDiscoveryTimeout?



  • From documentation:

    Sets the maximum search time for Bluetooth Low Energy device search to timeout in milliseconds. If timeout is 0 the discovery runs until stop() is called.
    
    This reflects the fact that the discovery process for Bluetooth Low Energy devices is mostly open ended. The platform continues to look for more devices until the search is manually stopped. The timeout ensures that the search is aborted after timeout milliseconds. Of course, it is still possible to manually abort the discovery by calling stop().
    
    The new timeout value does not take effect until the device search is restarted. In addition the timeout does not affect the classic Bluetooth device search. Depending on the platform the classic search may add more time to the total discovery process beyond timeout.
    

    However, this is not what I'm observing. When I call m_deviceDiscoveryAgent.setLowEnergyDiscoveryTimeout(5000); , I would expect the low energy discovery to stop after 5 seconds, and receive the signal finished(). Instead, the search takes more than 5 seconds every single time, and most of the time it takes more than 20 seconds, sometimes even over a minute.

    The biggest problem though is that the BLE discovery completely clogs the event loop, so I can't even set up my own timer to call the "stop()" slot - it will never be executed.

    The platform is Qt 5.11.3, Linux, BlueZ 5.50. As for the code, I am following examples from this page: https://doc.qt.io/qt-5/qtbluetooth-le-overview.html#establishing-a-connection

    So, the questions are:

    • What is the QBluetoothDeviceDiscoveryAgent::setLowEnergyDiscoveryTimeout() for, if not for setting the actual BLE discovery timeout?
    • Is this the right method to call? How can I actually limit the time to finish the discovery to e.g. 5 seconds?
    • Why is the event loop getting stuck during discovery?