Python new style signals and slot between thread and gui app

后端 未结 1 1710
感情败类
感情败类 2021-01-13 17:45

I am newbie to OOP and python. I am trying to emit signal from Qthread to Qt GUI main window using new style signals and slots.

This is the thread. Inside I will emi

相关标签:
1条回答
  • 2021-01-13 18:24

    The structure of your example is more or less right: but you are mixing up the old-style signal-slot syntax with the new-style.

    The signal definition should look like this:

    class OptimThread(QtCore.QThread):
        signalUpdateMessageDialog = QtCore.pyqtSignal(int, str)
    

    The signal should be emitted like this:

        self.signalUpdateMessageDialog.emit(
            time.time() - start, 'Initialising...')
    

    And this is how the signal should be connected:

        self.optimThread.signalUpdateMessageDialog.connect(
            self.updateMessageDialog)
    

    With the new-style syntax, there is never any need to use SIGNAL() or SLOT(), and it is never necessary to specify the C++ signature.

    For further details, see New-style Signal and Slot Support in the PyQt4 reference.

    0 讨论(0)
提交回复
热议问题