PyQt5: How do you call a method when there is a signal with the same name

344 views Asked by At

I'm trying to use QBluetoothDeviceDiscoveryAgent via PyQt5.

There is a signal name error. I have been able to successfully connect it (like this: self.error.connect(self.on_error)) and confirm that it is working.

However, there is also a method named error. How can you call this method in Python?

I was expecting something like error_, but I don't see anything in dir(QBluetoothDeviceDiscoveryAgent) that looks useful:

['DiscoveryMethod', 'DiscoveryMethods', 'Error', 'GeneralUnlimitedInquiry', 'InputOutputError', 'InquiryType', 'InvalidBluetoothAdapterError', 'LimitedInquiry', 'NoError', 'PoweredOffError', 'UnknownError', 'UnsupportedDiscoveryMethod', 'UnsupportedPlatformError', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattr__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'blockSignals', 'canceled', 'childEvent', 'children', 'connectNotify', 'customEvent', 'deleteLater', 'destroyed', 'deviceDiscovered', 'disconnect', 'disconnectNotify', 'discoveredDevices', 'dumpObjectInfo', 'dumpObjectTree', 'dynamicPropertyNames', 'error', 'errorString', 'event', 'eventFilter', 'findChild', 'findChildren', 'finished', 'inherits', 'inquiryType', 'installEventFilter', 'isActive', 'isSignalConnected', 'isWidgetType', 'isWindowType', 'killTimer', 'lowEnergyDiscoveryTimeout', 'metaObject', 'moveToThread', 'objectName', 'objectNameChanged', 'on_deviceDiscovered', 'on_error', 'on_finished', 'parent', 'property', 'pyqtConfigure', 'receivers', 'removeEventFilter', 'sender', 'senderSignalIndex', 'setInquiryType', 'setLowEnergyDiscoveryTimeout', 'setObjectName', 'setParent', 'setProperty', 'signalsBlocked', 'start', 'startTimer', 'staticMetaObject', 'stop', 'supportedDiscoveryMethods','thread', 'timerEvent', 'tr']
1

There are 1 answers

0
eyllanesc On BEST ANSWER

You have to call the function directly:

print(your_QBluetoothDeviceDiscoveryAgent.error())

This will return a number that corresponds to the following table:

QBluetoothDeviceDiscoveryAgent::NoError                         0   No error has occurred.
QBluetoothDeviceDiscoveryAgent::PoweredOffError                 2   The Bluetooth adaptor is powered off, power it on before doing discovery.
QBluetoothDeviceDiscoveryAgent::InputOutputError                1   Writing or reading from the device resulted in an error.
QBluetoothDeviceDiscoveryAgent::InvalidBluetoothAdapterError    3   The passed local adapter address does not match the physical adapter address of any local Bluetooth device.
QBluetoothDeviceDiscoveryAgent::UnsupportedPlatformError        4   Device discovery is not possible or implemented on the current platform. The error is set in response to a call to start(). An example for such cases are iOS versions below 5.0 which do not support Bluetooth device search at all. This value was introduced by Qt 5.5.
QBluetoothDeviceDiscoveryAgent::UnsupportedDiscoveryMethod      5   One of the requested discovery methods is not supported by the current platform. This value was introduced by Qt 5.8.
QBluetoothDeviceDiscoveryAgent::UnknownError                  100   An unknown error has occurred.

If you want to get the most readable text then use:

print(your_QBluetoothDeviceDiscoveryAgent.errorString())