Reputation: 216
I know that there are 2 methods of multi-threading using QThreads, One is to subclass QThread and override the run() method, other is to create a QObject class and move it's instance to QThread. the latter is said to be a better practice.
I found out that subclassing QThread does provide a finished
method which can be used but when creating a separate QObject as a worker thread, QThread will no longer emit the finished
signal. It seems that the QThrean run method creates an event loop which when is re-implemented, returns the function and emits a finished
signal. but for in case of a worker class we will need to call a quit()
method on the QThread object.
Is this correct? Does it not make subclassing QThread more flexible to use?
Upvotes: 3
Views: 221
Reputation: 244003
When the run method is overridden then the logic is implemented there so you can know when it ends, but in the case of moving a QObject to a QThread there is no way to determine when the QObject logic is finished executing.
An alternative is to create a finished signal that you emit when you consider that the QObject logic ends.
Upvotes: 2