[Interest] Question about QFutureWatcher<void> monitoring a QFuture<T>

Ivan Solovev ivan.solovev at qt.io
Thu Sep 29 12:35:01 CEST 2022


Hi Sean,

I'm not a QtConcurrent expert, but it looks like the reason for the error message is that an implicit conversion between QFuture<void> and QFuture<T> was removed in Qt 6. The recommended approach is to explicitly use a corresponding QFuture<void> constructor.
See the details in the documentation: https://doc.qt.io/qt-6/qtcore-changes-qt6.html#implicit-conversions-between-qfuture-and-other-types

Best regards,
Ivan

________________________________
From: Interest <interest-bounces at qt-project.org> on behalf of Sean Murphy via Interest <interest at qt-project.org>
Sent: Wednesday, September 28, 2022 4:15 PM
To: interest at qt-project.org <interest at qt-project.org>
Subject: [Interest] Question about QFutureWatcher<void> monitoring a QFuture<T>

In the Qt Docs, at the bottom of QFutureWatcher's Detailed
Description section there's this statement:
  Any QFuture<T> can be watched by a QFutureWatcher<void> as
  well. This is useful if only status or progress information
  is needed; not the actual result data.

That statement fits what I'm trying to do - I only need the
status/progress information. So I attempt the lines:
  QFutureWatcher<void> watcher;
  watcher.setFuture(QtConcurrent::mappedReduced(list, mapped, reduce));

This fails to compile with the error message:
  No viable conversion from 'QFuture<int>' to 'const QFuture<void>'
Where my mapped() function has the form
  U function(const T &t);
And my reduce() function has the form
  void function(int &result, const U &intermediate)

If I explicitly cast the mappedReduced() return value to a QFuture<void>:
  watcher.setFuture(static_cast<QFuture<void>>(
             QtConcurrent::mappedReduced(list, mapped, reduce)));

It compiles and seems to run fine, but I just wanted to double
check this was intended behavior, or if there was a better way
to do it? From the line in the docs, I assumed that the original
assignment was fine and I wouldn't need to explicitly cast.

Sean






This e-mail, including any attached files, may contain confidential information, privileged information and/or trade secrets for the sole use of the intended recipient. Any review, use, distribution, or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive information for the intended recipient), please contact the sender by reply e-mail and delete all copies of this message.
_______________________________________________
Interest mailing list
Interest at qt-project.org
https://lists.qt-project.org/listinfo/interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20220929/df391513/attachment.htm>


More information about the Interest mailing list