Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.7.2
-
None
-
Linux anatoliy-202311 6.10.2-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 27 Jul 2024 16:49:55 +0000 x86_64 GNU/Linux
Description
Currently if results provided out of order, QFutureWatcher emits hard interpretable signals.
Let's consider the following code:
#include <QtCore/QtCore> #include <QtConcurrent/QtConcurrent> int main(int argc, char * argv[]) { QCoreApplication a{argc, argv}; const auto f = [](QPromise<int> & promise) { int result = 0; promise.emplaceResultAt(1, result); promise.emplaceResultAt(0, result); promise.emplaceResultAt(2, result); }; QFutureWatcher<int> futureWatcher; futureWatcher.setFuture(QtConcurrent::run(f)); const auto onResultReadyAt = [](int resultIndex) { qInfo() << resultIndex; }; futureWatcher.connect(&futureWatcher, &QFutureWatcherBase::resultReadyAt, onResultReadyAt); const auto onResultsReadyAt = [](int beginIndex, int endIndex) { // Q_ASSERT(beginIndex <= endIndex); // fires qInfo() << beginIndex << endIndex; }; futureWatcher.connect(&futureWatcher, &QFutureWatcherBase::resultsReadyAt, onResultsReadyAt); futureWatcher.waitForFinished(); QTimer::singleShot(0, qApp, &QCoreApplication::quit); return a.exec(); }
Currently output is:
1 0 0 2 0 1 2 3 2
But expected output is:
1 1 1 0 0 0 2 2 2
Another connected problem.
The following code results in no resultReadyAt emitted at all (note, that zero-indexed result is not present), but resultsReadyAt contains a mess:
for (int i = 99; i > 0; --i) { promise.emplaceResultAt(i, result); }
For the next code resultsReadyAt emitted for each emplaceResultAt (timely/immidiately), but all resultReadyAt spammend all at once right after emplaceResultAt(0, result); is called. They spammed in-order.
for (int i = 99; i >= 0; --i) { promise.emplaceResultAt(i, result); }
It is generally expected, that resultReady to be emitted in a timely manner in long running tasks, that produce multiple results out of order, not all at once.
setPendingResultsLimit setting has no effect on above problems.