2

Will the finished() signal of QFutureWatcher always be fired, even if the concurrent job that the QFuture represents has completed before the QFutureWatcher is attached to the QFuture?

Consider the following example:

// Start some computation.
QFuture<int> future = QtConcurrent::run(...);

// [A] At this point some time may pass where the computation might finish concurrently

// Instaciate watcher
QFutureWatcher<int> watcher;

// Instantiate an object to receive singal
MyClass myObject;

// Connect slot to watcher's finished() signal
connect(&watcher, SIGNAL(finished()), &myObject, SLOT(handleFinished()));

// Attach watcher to the future
watcher.setFuture(future);

// [B] Will the handleFinished() slot be called at this point even if the concurrent job already completed in point [A] above?

And, most importantly, if this does not happen, how can I make the handleFinished() slot always be called in this case?

Mr. Developerdude
  • 9,118
  • 10
  • 57
  • 95
  • I wrote a small test program to verify this, and the answer is luckily YES, the signal will be fired in this case. I will add this as an answer if it is useful to you. – Mr. Developerdude May 24 '18 at 21:27

0 Answers0