A thread updating GUI in PySide6
Solved
Qt for Python
-
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())
-
@AlexP11223
It's much simpler to use Qt's asynchronous nature e.g. QTcpServer. No need for threads, multiprocessing or blocking. -