Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-84702

Make QPromise accessible inside user function passed to QtConcurrent::run()

    XMLWordPrintable

Details

    • User Story
    • Resolution: Done
    • P2: Important
    • None
    • 6.0
    • Core: Threads
    • None
    • 13
    • Qt6_Foundation_ Sprint 14, Qt6_Foundation_Sprint 15, Qt6_Foundation_Sprint 16

    Description

      QtConcurrent::run(Function f) could accept the Function that takes QPromise<T> as an argument. In this way we would enable progress reporting, canceling or suspending the task from inside working thread. Alternatively, instead of overloading the run() method, we could add a new one called e.g. runWithPromise(). The Function could be of the form:

      auto future = QtConcurrent::runWithPromise([] (QPromise<T>& implicitPromise, /* my args follow */ ...) {
        // Note: implicitPromise is the object provided by QtConcurrent, not by the user
        // do something with implicitPromise, this would update the future returned by QtConcurrent::run(). 
      });
      

      Most probably it wasn't enabled so far because QFutureInterface<T> was not an official public API. But since we are now enabling it with QPromise, we may do it!

      The idea was initially suggested here: (https://codereview.qt-project.org/c/qt/qtbase/+/300337), with some follow up comments. Potentially it may influence the API or usage of QPromise.

      Update: looking at what Creator has it seems like it may make sense to do it also for other QtConcurrent methods.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              jkobus Jarek Kobus
              jkobus Jarek Kobus
              Maurice Kalinowski Maurice Kalinowski
              Alex Blasche Alex Blasche
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes