connect(), disconnect() and emit() methods that implement the associated functionality.New signals should only be defined in sub-classes of QObject.They must be part of the class definition and cannot be dynamically added as class attributes after the class has been defined.
==>
在PyQt5中,
class QTd(QtCore.QThread):
    msig = QtCore.pyqtSignal(str, str)
    psig = QtCore.pyqtSignal(QtWidgets.QPushButton, bool)
    def __init__(self, fi, table, pbutton, sbox, parent = None):
        super().__init__(parent)
        self.fi = fi
        self.table = table
        self.pbutton = pbutton
        self.sbox = sbox
        self.msig.connect(self.showmbox)
        self.psig.connect(self.setpb)
==>
msig和psig是class variable, 
self.fi, self.table, self.pbutton, self.sbox是instance variable,
在此msig和psig是bound signal, 
(<class 'PyQt5.QtCore.pyqtBoundSignal'>)
如果宣告在class QTd的__init__底下,變成
self.msig = QtCore.pyqtSignal(str, str)
self.psig = QtCore.pyqtSignal(QtWidgets.QPushButton, bool)
那麼self.msig和self.psig就變成unbound signal, 
(<class 'PyQt5.QtCore.pyqtSignal'>)
unbound signal就沒有connect() method了。
詳參:
 
沒有留言:
張貼留言