How can I send a list object from a QThread thread to the UI's main thread?

前端 未结 1 1087
无人及你
无人及你 2021-01-24 06:06

I have written this example code to try and figure out how to communicate between a background thread, and the main thread. As I understand it, a thread cannot simply interact w

1条回答
  •  粉色の甜心
    2021-01-24 06:46

    You can define a custom signal, which can be safely emitted across threads:

    from PySide.QtCore import Signal
    
    class Gui(QWidget):
        def initUI(self):
            ...
            bgThread.dataReceived.connect(lambda data: lbl2.setText(str(data)))
    
    class BackgroundThread(QThread):
        dataReceived = Signal(list)
        ...
    
        def _summary(self):
            ...
            self.dataReceived.emit(data)
    

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