Details
-
Bug
-
Resolution: Duplicate
-
P2: Important
-
None
-
6.0
-
None
Description
If an object of move-only type is used in pair with QFuture, we cannot use simple APIs to access the stored value such as result() or resultAt(). Example:
QFutureInterface<std::unique_ptr<int>> iface; iface.reportResult(std::make_unique<int>(42)); // add 42 ptr to int into storage iface.resultReference(0); // OK, returns const T & auto future = iface.future(); future.resultAt(0); // Error, returns T instead of const T &
This happens despite the fact that resultAt() directly calls resultReference(), so we just lose a reference there (and also forced to copy an object).
It is unclear, why we always return T instead of const T & (as opposed to QFutureInterface function) - there's no detachment or anything in between.
Anyhow, I found a single possibility to get the results: using QFuture::const_iterator as they always return references (which is clumsy to use).
—
The issue exists in prior versions (e.g. 5.15) but unlikely we can change the APIs there, so Qt6 is the best bet.