Hi again!
Basically I want to keep my GUI responsive while, for example, processing data in a loop. So I guess I would have to do that processing in another thread.
If I want to wait for a thread to finish before continuing in my main thread I would have to use a QEventLoop, right?
Here is my code which creates a new thread and does what it should, but doesn’t seem to exit the QEventLoop (“end” doesn’t get printed out):
MyWorker w;
QThread t;
QEventLoop l;
connect(&t, &QThread::started, &w, &MyWorker::doLotsOfStuff);
connect(&t, &QThread::finished, &l, &QEventLoop::quit);
qDebug() << "begin";
w.moveToThread(&t);
t.start();
l.exec();
qDebug() << "end";
What am I doing wrong?
Help is appreciated! :)
↧