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

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

XMLWordPrintable

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

      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.

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

            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

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes