I think I might misunderstood several concepts in Qt\'s threading,
In my window class, which is derived from QWidget:
class Widget
{
Q_OBJECT
public:
Widget::dowork()
is executed on the main thread (on which the GUI runs), that's why it blocks. It doesn't matter that it was called by a QThread.
The correct way to execute code on another thread is to first move a QObject instance to a QThread using QObject::moveToThread()
, and then connect the started()
signal of the QThread to the slot of the QObject instance that you want executed.
If you want to know more: http://blog.qt.digia.com/2010/06/17/youre-doing-it-wrong/
Another issue with your code is that you're trying to move a QWidget-derived object to another thread. This is not allowed. QWidget instances must remain on the main thread. Instead, you should subclass from QObject.
Yet another issue with the code is that you're doing this in the constructor. Moving the object to another thread while it's not fully constructed yet is just asking for trouble.