Calling methods of PyQt objects in a thread.
-
Im relatively new to PyQt. Can someone help explain the best way to call something like
window.show()
from a thread? When I run this, my thread (and program) terminates without an error.
My program is doing some work in a thread before showing the main window. Using
label.SetText()
on a label to display progress works, but when using
window.show()
the program stops.
I’m using Qt Designer to make my user interfaces.
Thank you! -
window.show()
You can't. Because Qt does not allow any UI operations to be performed from any thread other than the main thread used to display the UI. That actually applies just as much to
QLabel.setText()
as it does toQWidget.show()
, so you are lucky if you see either of these work from a thread.As a general observation, especially if you are new to Qt/PyQt. Threads are the last thing you want to use if you can avoid it. A large number of beginners try to use threads from the start, for no reason/they run into difficulties. So the first thing to ask yourself is why you need a thread at all.
BTW Qt has
QProgressBar
orQProgressDialog
classes to display progress.