这个应该和python类有关系。
类那块没好好学,专业解释也不太清楚。
写一下我发现的不同吧。class A:
a = 1
def __init__(self):
self.b = 2
print(dir(A))
这里我发现类A中的属性只有a而没有b,所以类里面的__init__生成的变量应该不能算是类的属性,应该只能算是类中函数可以共用的变量,类似闭包。(在其他方法中定义变量到另一个函数中无法使用。)
然后,在楼主的代码里查看了一下这两个信号的类型。
发现第一个是<class 'PyQt5.QtCore.pyqtBoundSignal'>
第二个是<class 'PyQt5.QtCore.pyqtSignal'>
顺便help了一下,第一个是class pyqtBoundSignal(builtins.object)
| Methods defined here:
|
| __call__(self, /, *args, **kwargs)
| Call self as a function.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| connect(...)
| connect(slot, type=Qt.AutoConnection, no_receiver_check=False)
|
| slot is either a Python callable or another signal.
| type is a Qt.ConnectionType.
| no_receiver_check is True to disable the check that the receiver's C++
| instance still exists when the signal is emitted.
|
| disconnect(...)
| disconnect([slot])
|
| slot is an optional Python callable or another signal. If it is omitted
| then the signal is disconnected from everything it is connected to.
|
| emit(...)
| emit(*args)
|
| *args are the values that will be passed as arguments to all connected
| slots.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| signal
| The signature of the signal that would be returned by SIGNAL()
显然发现了connect方法。
但是第二个是一个未绑定的信号。
翻了一下pyqt5的文档。发现了这么一段。Unbound and Bound Signals
A signal (specifically an unbound signal) is a class attribute. When a signal is referenced as an attribute of an instance of the class then PyQt5 automatically binds the instance to the signal in order to create a bound signal. This is the same mechanism that Python itself uses to create bound methods from class functions.
让开!我来翻译!(渣翻译,见谅。)
[b]一个信号(特别是一个未绑定的信号)是类中的一个属性当信号作为属性被实例化后,PyQt5会自动绑定到实例信号并创建一个绑定的信号。这和Python自身创建绑定方法的功能类似。[/b]
好吧,根据文档,信号得是类的属性才可以。但放在__init__里并不是一个属性,是个啥,不知道,暂且叫他局部变量吧。
@~风介~ 介哥好懒!楼主换了一个萌萌哒的头像!
|