diff options
author | Olivier Goffart <olivier.goffart@nokia.com> | 2010-08-23 14:49:06 (GMT) |
---|---|---|
committer | Olivier Goffart <olivier.goffart@nokia.com> | 2010-08-23 15:14:04 (GMT) |
commit | b7fd2930986a9be5dd6115bfc4a5c5c517344371 (patch) | |
tree | 48d4c43c0c2ea67fe48ca7370a520837ed3b1ddd | |
parent | dae23694cb89b853785a5772cc7e0477f65ac5bf (diff) | |
download | Qt-b7fd2930986a9be5dd6115bfc4a5c5c517344371.zip Qt-b7fd2930986a9be5dd6115bfc4a5c5c517344371.tar.gz Qt-b7fd2930986a9be5dd6115bfc4a5c5c517344371.tar.bz2 |
QFutureWatcher: display a warning when connecting after calling setFuture()
Reviewed-by: brad
-rw-r--r-- | src/corelib/concurrent/qfuturewatcher.cpp | 9 | ||||
-rw-r--r-- | tests/auto/qfuturewatcher/tst_qfuturewatcher.cpp | 24 |
2 files changed, 32 insertions, 1 deletions
diff --git a/src/corelib/concurrent/qfuturewatcher.cpp b/src/corelib/concurrent/qfuturewatcher.cpp index d4573c6..21b0789 100644 --- a/src/corelib/concurrent/qfuturewatcher.cpp +++ b/src/corelib/concurrent/qfuturewatcher.cpp @@ -359,6 +359,15 @@ void QFutureWatcherBase::connectNotify(const char * signal) Q_D(QFutureWatcherBase); if (qstrcmp(signal, SIGNAL(resultReadyAt(int))) == 0) d->resultAtConnected.ref(); +#ifndef QT_NO_DEBUG + if (qstrcmp(signal, SIGNAL(finished())) == 0) { + if (futureInterface().isRunning()) { + //connections should be established before calling stFuture to avoid race. + // (The future could finish before the connection is made.) + qWarning("QFutureWatcher::connect: connecting after calling setFuture() is likely to produce race"); + } + } +#endif } void QFutureWatcherBase::disconnectNotify(const char * signal) diff --git a/tests/auto/qfuturewatcher/tst_qfuturewatcher.cpp b/tests/auto/qfuturewatcher/tst_qfuturewatcher.cpp index c53c67a..8b52761 100644 --- a/tests/auto/qfuturewatcher/tst_qfuturewatcher.cpp +++ b/tests/auto/qfuturewatcher/tst_qfuturewatcher.cpp @@ -81,6 +81,7 @@ private slots: void incrementalMapResults(); void incrementalFilterResults(); void qfutureSynchornizer(); + void warnRace(); }; QTEST_MAIN(tst_QFutureWatcher) @@ -466,12 +467,12 @@ void tst_QFutureWatcher::toMuchProgress() ProgressObject o; QFutureWatcher<void> f; - f.setFuture((new ProgressEmitterTask())->start()); QObject::connect(&f, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); #ifdef PRINT QObject::connect(&f, SIGNAL(progressValueChanged(int)), &o, SLOT(printProgress(int))); #endif QObject::connect(&f, SIGNAL(progressValueChanged(int)), &o, SLOT(registerProgress(int))); + f.setFuture((new ProgressEmitterTask())->start()); QTestEventLoop::instance().enterLoop(5); QVERIFY(!QTestEventLoop::instance().timeout()); @@ -886,6 +887,27 @@ void tst_QFutureWatcher::qfutureSynchornizer() QVERIFY(t.elapsed() < taskCount * 10); } +class DummyObject : public QObject { + Q_OBJECT +public slots: + void dummySlot() {} +}; + +void tst_QFutureWatcher::warnRace() +{ +#ifndef QT_NO_DEBUG + QTest::ignoreMessage(QtWarningMsg, "QFutureWatcher::connect: connecting after calling setFuture() is likely to produce race"); +#endif + QFutureWatcher<void> watcher; + DummyObject object; + + QFuture<void> future = QtConcurrent::run(sleeper); + watcher.setFuture(future); + connect(&watcher, SIGNAL(finished()), &object, SLOT(dummySlot())); + future.waitForFinished(); +} + + #include "tst_qfuturewatcher.moc" #else |