Python new style signals and slot between thread and gui app

…衆ロ難τιáo~ 提交于 2019-12-01 06:28:27

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!