PyQt4:以新风格连接自定义信号和插槽

时间:2015-12-01 11:25:06

标签: python signals pyqt4 slot

我写了下面的类,它有一个名为signal_incremented

的自定义信号
class QThread_Sniffer(QtCore.QThread):

    signal_incremented = pyqtSignal(int, name="incremented")

    def __init__(self):
        QtCore.QThread.__init__(self)

    def run(self):
        #
        # do something
        #

        self.signal_incremented.emit(42)

现在我想将此信号连接到另一个类的插槽,该插槽正在创建此QThread的实例。

这有效

class Dialog_Capturing(QDialog):

    def __init__(self):
        QDialog.__init__(self)
        self.lcdNumber_packetCount = QLCDNumber()
        self.worker_sniffer = QThread_Sniffer()
        self.worker_sniffer.signal_incremented[int].connect(self.counterIncremented)

    @pyqtSlot(int)
        def counterIncremented(self, number):
            self.lcdNumber_packetCount.display(number)

但我想使用连接插槽和信号的新风格,但在这种情况下我不知道如何使用它。

self.connect(
    self.worker_sniffer.signal_incremented,
    SIGNAL(), # < ===== What do I need to put here?
    self.counterIncremented
)

0 个答案:

没有答案