Communication between threads in PySide

后端 未结 1 1598
轻奢々
轻奢々 2021-01-31 21:03

I have a thread which produces some data (a python list) and which shall be available for a widget that will read and display the data in the main thread. Actually, I\'m using Q

相关标签:
1条回答
  • 2021-01-31 21:54

    I think this should work with PySide. if not work please report a bug on PySide bugzilla(http://bugs.openbossa.org/) with a small test case:

    class Thread(QThread):
      dataReady = Signal(object)
    
      def run(self):
        while True:
          self.data = slowly_produce_data()
          # this will add a ref to self.data and avoid the destruction 
          self.dataReady.emit(self.data) 
    
    class Widget(QWidget):
      def __init__(self):
        self.thread = Thread()
        self.thread.dataReady.connect(self.get_data, Qt.QueuedConnection)
        self.thread.start()
    
      def get_data(self, data):
        self.data = data
    
      def paintEvent(self, event):
        paint_somehow(self.data)
    
    0 讨论(0)
提交回复
热议问题