You can use QFuture<T> QtConcurrent::run ( Function function, ... ) to run some execution inside a separate thread, and then use QFutureWatcher to get the result. You will not need to call movetoThread .
Basically something like:
QFutureWatcher<T>* watch = new QFuture(0); connect(watch, SIGNAL(finished()), this, SLOT(handleResult())); QFuture<T> future = QtConcurrent::run( myObj, &QMyObject::theSlot(), args...); watch.setFuture(future); ....
QtConcurrent::run will schedule the launch of this object in some thread. It does not block. On the other hand, QFuture::result() blocks until a result is obtained if the calculation is still ongoing. To do this, you need another object to be notified when the calculation is completed using finished() . I cannot come up with a better design for your problem in Qt.
source share