Attach all signal spies before setting the watcher's future.

Attaching spies afterwards was provoking a warning during tests:
QFutureWatcher::connect: connecting after calling setFuture() is likely to produce race

Change-Id: I6ee8c3613cecebd1c69b0337139d8a19a33f4a11
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
Edward Welbourne 2015-10-27 12:23:42 +01:00
parent 70eb137768
commit ada4b4aaa5

View File

@ -313,10 +313,16 @@ void tst_QFutureWatcher::futureSignals()
// (QSignalSpy does not trigger it.)
connect(&f, SIGNAL(resultReadyAt(int)), &object, SLOT(resultReadyAt(int)));
a.reportStarted();
f.setFuture(a.future());
QSignalSpy progressSpy(&f, &QFutureWatcher<void>::progressValueChanged);
QSignalSpy finishedSpy(&f, &QFutureWatcher<void>::finished);
QSignalSpy resultReadySpy(&f, &QFutureWatcher<void>::resultReadyAt);
QVERIFY(progressSpy.isValid());
QVERIFY(finishedSpy.isValid());
QVERIFY(resultReadySpy.isValid());
f.setFuture(a.future());
const int progress = 1;
a.setProgressValue(progress);
QTest::qWait(10);
@ -324,12 +330,6 @@ void tst_QFutureWatcher::futureSignals()
QCOMPARE(progressSpy.takeFirst().at(0).toInt(), 0);
QCOMPARE(progressSpy.takeFirst().at(0).toInt(), 1);
QSignalSpy finishedSpy(&f, &QFutureWatcher<void>::finished);
QSignalSpy resultReadySpy(&f, &QFutureWatcher<void>::resultReadyAt);
QVERIFY(finishedSpy.isValid());
QVERIFY(resultReadySpy.isValid());
const int result = 10;
a.reportResult(&result);
QTest::qWait(10);
@ -427,16 +427,15 @@ void tst_QFutureWatcher::disconnectRunningFuture()
QFuture<int> f = a.future();
QFutureWatcher<int> *watcher = new QFutureWatcher<int>();
watcher->setFuture(f);
SignalSlotObject object;
connect(watcher, SIGNAL(resultReadyAt(int)), &object, SLOT(resultReadyAt(int)));
QSignalSpy finishedSpy(watcher, &QFutureWatcher<int>::finished);
QSignalSpy resultReadySpy(watcher, &QFutureWatcher<int>::resultReadyAt);
QVERIFY(finishedSpy.isValid());
QVERIFY(resultReadySpy.isValid());
watcher->setFuture(f);
SignalSlotObject object;
connect(watcher, SIGNAL(resultReadyAt(int)), &object, SLOT(resultReadyAt(int)));
const int result = 10;
a.reportResult(&result);