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

QFuture does not allow to access a move-only object via resultAt()/result()

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P2: Important
    • None
    • 6.0
    • Core: Threads
    • 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.

      Attachments

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

        Activity

          People

            cnn Qt Core & Network
            agolubev Andrei Golubev
            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