for some time I am fiddly now to get a massive time/cputime drain action running behind a nicly responding UI. Unfortunatly I can\'t seem to get it running and \"I think\" t
Proper usage of QThread
is a common problem among Qt users. This blog post at Qt Labs explains it nicely.
In short, you should not subclass QThread
to contain code that you want to run in that thread. You should wrap your code up in a QObject
subclass, instantiate it and use a QObject::moveToThread
to move your object into the QThread
context so that processing will occur in the context of that QThread
. You can then have slots in your QObject
subclass that can safely be connected to another thread but will run in the context you expect.
Some may argue that subclassing QThread
should be fine if you can easily fit what you want to do inside the run()
method and don't need much (or any) external interaction but even in this simple case I would favor a separate class for better encapsulation.