I'm trying to learn how to use QThreads in a PyQt Gui application. I have stuff that runs for a while, with (usually) points where I could update a Gui, but I would like to split the main work out to its own thread (sometimes stuff gets stuck, and it would be nice to eventually have a cancel/try again button, which obviously doesn't work if the Gui is frozen because the Main Loop is blocked).
I've read https://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/. That page says that re-implementing the run
method is not the way to do it. The problem I am having is finding a PyQt example that has a main thread doing the Gui and a worker thread that does not do it that way. The blog post is for C++, so while it's examples do help, I'm still a little lost. Can someone please point me to an example of the right way to do it in Python?
threading.Thread
, etc.)? If not, you may want to work through some examples of that first. (Also see Threading in a PyQt application: Use Qt threads or Python threads to see if you even need QThread here.) – Cochabambathreading.Thread
exists, but have not used it before. I did a lot of searching, and even saw the first link, skimmed it, sawdef run
and moved on, not realizing the showed both ways! – Ciracirca