Commit a016c7f4 authored by Eike Ziller's avatar Eike Ziller

RunExtensions: Connect before setting future

"connecting after calling setFuture() is likely to produce race"

Change-Id: Ia4eecf977fc0a89aff5ac72e42c877d1297d263d
Reviewed-by: Vikas Pachdha's avatarVikas Pachdha <vikas.pachdha@qt.io>
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
parent 5eeecdb1
......@@ -504,12 +504,12 @@ template <typename R, typename T>
const QFuture<T> &onResultReady(const QFuture<T> &future, R *receiver, void(R::*member)(const T &))
{
auto watcher = new QFutureWatcher<T>();
watcher->setFuture(future);
QObject::connect(watcher, &QFutureWatcherBase::finished, watcher, &QObject::deleteLater);
QObject::connect(watcher, &QFutureWatcherBase::resultReadyAt, receiver,
[receiver, member, watcher](int index) {
(receiver->*member)(watcher->future().resultAt(index));
});
watcher->setFuture(future);
return future;
}
......@@ -523,11 +523,11 @@ template <typename T, typename Function>
const QFuture<T> &onResultReady(const QFuture<T> &future, QObject *guard, Function f)
{
auto watcher = new QFutureWatcher<T>();
watcher->setFuture(future);
QObject::connect(watcher, &QFutureWatcherBase::finished, watcher, &QObject::deleteLater);
QObject::connect(watcher, &QFutureWatcherBase::resultReadyAt, guard, [f, watcher](int index) {
f(watcher->future().resultAt(index));
});
watcher->setFuture(future);
return future;
}
......@@ -540,11 +540,11 @@ template <typename T, typename Function>
const QFuture<T> &onResultReady(const QFuture<T> &future, Function f)
{
auto watcher = new QFutureWatcher<T>();
watcher->setFuture(future);
QObject::connect(watcher, &QFutureWatcherBase::finished, watcher, &QObject::deleteLater);
QObject::connect(watcher, &QFutureWatcherBase::resultReadyAt, [f, watcher](int index) {
f(watcher->future().resultAt(index));
});
watcher->setFuture(future);
return future;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment