![](/img/trans.png)
[英]PyQt5: Using QtDesigner, how do you connect a signal with a slot/callable defined in a module
[英]PyQt5: How do you call a method when there is a signal with the same name
我试图用QBluetoothDeviceDiscoveryAgent通过PyQt5。
信号名称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())
这将返回一个与下表相对应的数字:
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())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.