Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. A thread updating GUI in PySide6
Forum Updated to NodeBB v4.3 + New Features

A thread updating GUI in PySide6

Scheduled Pinned Locked Moved Solved Qt for Python
qt for python
2 Posts 2 Posters 1.1k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    AlexP11223
    wrote on last edited by
    #1

    I need to listen for messages from other processes and do something with GUI when a message is received, e.g. creating a new window.

    So I use multiprocessing.connection for the first part, but of course I need a separate thread to unblock the UI thread.

    What is the right way to do it in PySide6? I guess I need a QThread, but I am not sure how to use it here.

    import multiprocessing.connection
    import sys
    from PySide6.QtWidgets import QApplication
    
    if __name__ == '__main__':
        # do this in a separate thread 
        listener = multiprocessing.connection.Listener(('localhost', 6000), 'AF_INET')
        while True:
            client = listener.accept()
            s = client.recv()
            client.close()
            widget = MyWindow()
            widget.set_content(s) 
            widget.show()
    
        # UI thread 
        app = QApplication([])
    
        sys.exit(app.exec())
    
    JonBJ 1 Reply Last reply
    0
    • A AlexP11223

      I need to listen for messages from other processes and do something with GUI when a message is received, e.g. creating a new window.

      So I use multiprocessing.connection for the first part, but of course I need a separate thread to unblock the UI thread.

      What is the right way to do it in PySide6? I guess I need a QThread, but I am not sure how to use it here.

      import multiprocessing.connection
      import sys
      from PySide6.QtWidgets import QApplication
      
      if __name__ == '__main__':
          # do this in a separate thread 
          listener = multiprocessing.connection.Listener(('localhost', 6000), 'AF_INET')
          while True:
              client = listener.accept()
              s = client.recv()
              client.close()
              widget = MyWindow()
              widget.set_content(s) 
              widget.show()
      
          # UI thread 
          app = QApplication([])
      
          sys.exit(app.exec())
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @AlexP11223
      It's much simpler to use Qt's asynchronous nature e.g. QTcpServer. No need for threads, multiprocessing or blocking.

      1 Reply Last reply
      2
      • A AlexP11223 has marked this topic as solved on

      • Login

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