Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. PySide2 & Threading... how to set data on widget from thread?

PySide2 & Threading... how to set data on widget from thread?

Scheduled Pinned Locked Moved Unsolved General and Desktop
pyside2thread
5 Posts 2 Posters 2.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dariusz
    wrote on last edited by
    #1

    Hey

    So this is interesting one... in C++ I would just roll with QMetaObject::InvokeMethod(widgetobject,=,t=data{widgetobject.setText(t)},Qt::QueuedConnection);.... but in PySide2... how do I do this ? Or whats the proper way ?

    My "other" thread is a different library and runs using native threading.Thread from python and not Qt one...

    Hints?

    TIA

    eyllanescE 1 Reply Last reply
    0
    • D Dariusz

      Hey

      So this is interesting one... in C++ I would just roll with QMetaObject::InvokeMethod(widgetobject,=,t=data{widgetobject.setText(t)},Qt::QueuedConnection);.... but in PySide2... how do I do this ? Or whats the proper way ?

      My "other" thread is a different library and runs using native threading.Thread from python and not Qt one...

      Hints?

      TIA

      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by
      #2

      @Dariusz Use signals for send information

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      1 Reply Last reply
      1
      • D Offline
        D Offline
        Dariusz
        wrote on last edited by
        #3

        @eyllanesc said in PySide2 & Threading... how to set data on widget from thread?:

        @Dariusz Use signals for send information

        Yes I have a feeling thats what I need but what is the proper way of doing it ?

        class manager(QObject)
            sendData = Signal(object, str)
        
            def __init__():
                self.sendData.connect(self.applyData)
        
            ### Execute on MAIN Thread
            def applyData(self, object, data):
                object.setText(data)
        
            ### call from thread XXXX
            def sendIt(self, someWidget,data):
                self.sendData.emit(someWidget, data)
        
        Like this? How do I know if he uses QueuedConnection or DirectConnection ? 
        
        TIA
        1 Reply Last reply
        0
        • eyllanescE Offline
          eyllanescE Offline
          eyllanesc
          wrote on last edited by eyllanesc
          #4

          @Dariusz said in PySide2 & Threading... how to set data on widget from thread?:

          1. Do not implement the same logic in the same class so "manager" should only process the data and send it, then connect that signal to the GUI so that it updates the information.
          Class Worker(QObject):
              sendData = Signal(str)
              def process(self):
                  value = "foo"
                 self.sendData.emit(value)
          
          class GUI(QWidget):
              def apply_data(self, text):
                 self.foo.setText(text)
          
          worker = Worker()
          thread = QThread()
          worker.moveToThread(thread)
          
          gui = GUI()
          worker.sendData.connect(gui.apply_data)
          
          QTimer.singleShot(0, worker.process)
          
          1. By default in the connection AutoConnection is used so since the sender lives in the second thread and the receiver in the main thread then QueuedConnection will be used.

          If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

          D 1 Reply Last reply
          1
          • eyllanescE eyllanesc

            @Dariusz said in PySide2 & Threading... how to set data on widget from thread?:

            1. Do not implement the same logic in the same class so "manager" should only process the data and send it, then connect that signal to the GUI so that it updates the information.
            Class Worker(QObject):
                sendData = Signal(str)
                def process(self):
                    value = "foo"
                   self.sendData.emit(value)
            
            class GUI(QWidget):
                def apply_data(self, text):
                   self.foo.setText(text)
            
            worker = Worker()
            thread = QThread()
            worker.moveToThread(thread)
            
            gui = GUI()
            worker.sendData.connect(gui.apply_data)
            
            QTimer.singleShot(0, worker.process)
            
            1. By default in the connection AutoConnection is used so since the sender lives in the second thread and the receiver in the main thread then QueuedConnection will be used.
            D Offline
            D Offline
            Dariusz
            wrote on last edited by
            #5

            @eyllanesc said in PySide2 & Threading... how to set data on widget from thread?:

            @Dariusz said in PySide2 & Threading... how to set data on widget from thread?:

            1. Do not implement the same logic in the same class so "manager" should only process the data and send it, then connect that signal to the GUI so that it updates the information.
            Class Worker(QObject):
                sendData = Signal(str)
                def process(self):
                    value = "foo"
                   self.sendData.emit(value)
            
            class GUI(QWidget):
                def apply_data(self, text):
                   self.foo.setText(text)
            
            worker = Worker()
            thread = QThread()
            worker.moveToThread(thread)
            
            gui = GUI()
            worker.sendData.connect(gui.apply_data)
            
            QTimer.singleShot(0, worker.process)
            
            1. By default in the connection AutoConnection is used so since the sender lives in the second thread and the receiver in the main thread then QueuedConnection will be used.

            Hmmm thank you, but will this work with python Thread ? As the worker thread, I got is not Qt...

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved