PyQt5 QtBluetooth examples or documentation

Heads up! You've already completed this tutorial.

alvarojaviervargasm4 | 2021-05-21 23:30:14 UTC | #1

Hello.

I'm developing an application that communicate 2 devices with Bluetooth LE connection, I've been trying with PyBluez but it has been very difficult to get a stable version, so, I found an example (link) in the QT5 documentation for C++ and tried to port it to PyQt5 and added a few lines. So, when I executed it prints the following error, and don't know where to begin to fix it.

Any help or documentation that you could give me will be appreciated.

Error:

bash
Agent error
args (4,)
kwargs {}
qt.bluetooth: Dummy backend running. Qt Bluetooth module is non-functional.

PyQt5 Code

python
import sys
from PyQt5 import QtBluetooth as QtBt
from PyQt5 import QtCore


class Application(QtCore.QCoreApplication):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.scan_for_devices()
        self.exec()

    def display_status(self):
        print(self.agent.isActive(), self.agent.discoveredDevices())

    def show_info(self, info: QtBt.QBluetoothDeviceInfo):
        print('Device discovered')
        print(info)
        print(f'Name: {info.name()}')
        print(f'UUID: {info.deviceUuid()}')
        pass

    def agent_finished(self,*args, **kwargs):
        print('Agent finished')
        print(f'args {args}')
        print(f'kwargs {kwargs}')

    def agent_error(self,*args, **kwargs):
        print('Agent error')
        print(f'args {args}')
        print(f'kwargs {kwargs}')

    def scan_for_devices(self):
        self.agent = QtBt.QBluetoothDeviceDiscoveryAgent()
        self.agent.setLowEnergyDiscoveryTimeout(5000)

        self.agent.deviceDiscovered.connect(self.show_info)
        self.agent.finished.connect(self.agent_finished)
        self.agent.error.connect(self.agent_error)

        timer = QtCore.QTimer(self.agent)
        timer.start(1000)
        timer.timeout.connect(self.display_status)

        self.agent.start()


if __name__ == '__main__':
    app = Application(sys.argv)

Eolinwen | 2021-05-26 19:00:54 UTC | #2

Over 10,000 developers have bought Create GUI Applications with Python & Qt!
Create GUI Applications with Python & Qt5
Take a look

Downloadable ebook (PDF, ePub) & Complete Source code

Also available from Leanpub and Amazon Paperback

[[ discount.discount_pc ]]% OFF for the next [[ discount.duration ]] [[discount.description ]] with the code [[ discount.coupon_code ]]

Purchasing Power Parity

Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]

Hi alvarojaviervargasm4 and welcome to the forum,

The error that you get is that your Bluetooth module is not functional. You must not to have the Qt Bluetooth installed on your system or you have none Bluetooth key. For me, I don't get this error. However, they are something strange. Because I get nothing.

python
Python 3.9.5 (default, May  9 2021, 14:00:28)

[GCC 10.2.0] on linux runfile('/home/olivier/.config/JetBrains/PyCharmCE2021.1/scratches/bluetooth_module_test.py', wdir='/home/olivier/.config/JetBrains/PyCharmCE2021.1/scratches') True [] True [] True [] True [] Agent finished args () kwargs {} False [] False [] False [] False [] False [] False [] False [] False [] False [] False [] False [] False [] False [] False [] False [] False [] False [] False [] False [] False [] False [] False [] False [] False [] False [] False [] False [] False [] False [] False [] False [] False [] And yet my BT key is functional but it's a 5.0. Maybe this has an impact. Anyway, I don't understand your logic. Info is not declared. Then, it is normal that you have nothing in output. After I'm not a specialist and I know that's difficult to translate Qt in PyQt.


Packaging Python Applications with PyInstaller by Martin Fitzpatrick — This step-by-step guide walks you through packaging your own Python applications from simple examples to complete installers and signed executables.

More info Get the book

Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak

PyQt5 QtBluetooth examples or documentation was written by Martin Fitzpatrick .

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt.