簡體   English   中英

PyQt5:當信號同名時如何調用方法

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM