PyQt5:当有同名信号时如何调用方法

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

我正在尝试通过 PyQt5 使用 QBluetoothDeviceDiscoveryAgent

有一个信号名称error。我已经能够成功连接它(像这样:self.error.connect(self.on_error))并确认它正在工作。

不过,还有一个名为error的方法。如何在 Python 中调用此方法?

我期待 error_,但我在 dir(QBluetoothDeviceDiscoveryAgent) 中没有看到任何看起来有用的东西:

['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']

您必须直接调用该函数:

print(your_QBluetoothDeviceDiscoveryAgent.error())

这将 return 对应于以下 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.

如果您想获得最易读的文本,请使用:

print(your_QBluetoothDeviceDiscoveryAgent.errorString())