What you can do is create an object to perform all these tasks (inherit QObject for slots / signals). Suppose each task is defined as a separate function - it allows you to assign these functions to slots.
Then (general order of events):
- create an instance of the QThread object.
- create an instance of the class.
- Move the object to the stream using
YouClass->moveToThread(pThread) . - Now define a signal for each slot and connect these signals to the corresponding slots in your facility.
- Finally, start the thread using
pThread->start()
Now you can emit a signal to perform a specific task in the stream. You do not need the QThread subclass to use a regular class derived from QObject (so you can use slots / signals).
You can use one class in one thread to perform many operations (note: they will be queued). Or to make many classes in many flows (for start "in parallel").
I don't know python well enough to try the example here, so I wonβt: o
Note. The reason for the QThread subclass would be if you wanted to extend the functionality of the QThread class, i.e. add additional / stream related functions. QThread is a class that controls the thread and is not intended to use arbitrary / common tasks ... even if you can abuse it if you want :)
source share