[PyQt] Question on QThread methodology/idiom/conceptual use
Ira Gray
tkjthingone at gmail.com
Wed Feb 10 23:34:51 GMT 2016
Hello,
I'm currently at work so I don't have code I can share right this second,
but I had a sort of epiphany moment and I'm hoping to get some
clarification with how threading is normally intended to be executed in a
Qt app.
Backstory:
I'm using Python3 and PyQt5. I've been trying to make signals and slots and
moveToThread work for a couple days now and not having a lot of success. I
can implement the toy examples I find around the web, but when I try to
re-engineer the examples to do what I want, things start to break down.
What I've been trying to do is create two classes. One class handles a very
basic UI consisting of a couple buttons, and the other class houses a
couple recursive functions. Long running, but shortish loops. My goal/idea
was I'd have two threads. One main thread for the UI, and a second thread
for the long running functions. Pressing a button on the UI would
start/stop the functions dynamically, but the thread would constantly be
running regardless of if it had meaningful things to do or not.
Based on the examples I'd read on moveToThread, I thought this would be
somewhat simple. Setup some signals to pass information back and forth,
instantiate my two classes, and then pass the worker class off to a thread,
and presto I'm off to the races.
Only, I haven't been able to get it to work, and every example I've found
of moveToThread is moving an object with only one function/member, usually
called run.
Which brings me to my question:
*Does the idea of having a class that holds multiple functions live in
another thread permanently make sense? Can a thread even handle that? Is
there a better way?*
Thanks for any input,
I'm mostly self taught, so I'm worried I picked up a misconception
somewhere or I'm lacking some critical understanding of what's actually
going on under the hood.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160210/01631ad3/attachment.html>
More information about the PyQt
mailing list