[PyQt] Connecting and sending a message in bluetooth using python and PyQt5

David Boddie david at boddie.org.uk
Fri Apr 17 13:13:34 BST 2020


On Fri Apr 17 07:55:09 BST 2020, Jason Friedman wrote:

> I have been trying to connect to a Bluetooth device (regular, not low
> energy - an HC-06) using PyQt5 but with no success. I can connect to the
> same device using standard python calls.

Perhaps it would be useful to see the regular Python code.

> I am running Python 3.7 on MacOS
> 10.15.4. When I run the below code, I get the error: 'unknown error', I'd
> be happy to know what I am doing wrong, or a pointer to a python example (I
> could not find any online). I have managed to get the scanning for
> Bluetooth devices working using PyQt. My code is below:
> 
> **************
> import sys
> import bluetooth
> import os
> 
> from PyQt5.QtWidgets import QApplication, QWidget
> from PyQt5.QtCore import Qt
> from PyQt5 import QtBluetooth
> 
> class bluetoothTest(QWidget):
>     def __init__(self, parent = None):
>         super(bluetoothTest, self).__init__(parent)
>         
>         self.connectToRobot()
>         
>         self.app = QApplication(sys.argv)
>         self.win = QWidget()
>         self.win.show()
>         sys.exit(self.app.exec_())

You are already creating and starting a QApplication instance in your main
code. Does removing this help at all?

David


More information about the PyQt mailing list