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

Continuation on 'mapped' yields single result only

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 6.10.0 FF
    • 6.7.2
    • Core: QtConcurrent
    • None
    • Windows
    • 3
    • 3978f3d5e (dev), 4b18a8946 (dev), fe7cb2419 (6.9), 8a77fc074 (6.8), 78b97b984 (tqtc/lts-6.5)
    • Foundation Sprint 127, Foundation Sprint 128

    Description

      Consider the following complete example:

      #include <QCoreApplication>
      #include <numbers>
      #include <cmath>
      #include <QtConcurrentMap>
      
      int main(int argc, char* argv[])
      {
          QCoreApplication a(argc, argv);
      
          auto fCalculateArea = [](const double radius)
              {
                  return std::pow(radius, 2.0) * std::numbers::pi;
              };
          auto fFormatArea = [](const double area)
              {
                  return QString("%1 m²").arg(QString::number(area,'f'));
              };
      
          QList<double> vecInputs{2.0, 6.0, 9.0};
          auto future = QtConcurrent::mapped(vecInputs, fCalculateArea)
                            .then(fFormatArea);
          future.waitForFinished();
          qDebug() << "Number of inputs:" << vecInputs.size() <<
                      "Number of results:" << future.resultCount();
      } 

      future.resultCount() is 1 (despite 3 inputs for QtConcurrent::mapped).

      This is pretty unexpected behavior. I assume the QFuture of the first stage of the pipeline decays into a double (the input for the 2nd stage of the pipeline) implicitly via "result()", which does not take into account that more than one result exists.

      If this usage is not desired, it should (ideally) not compile, or at least be documented and show a runtime error message.

      See also https://forum.qt.io/topic/160852/continuation-not-working-with-qtconcurrent-mapped/19

      Attachments

        For Gerrit Dashboard: QTBUG-133522
        # Subject Branch Project Status CR V

        Activity

          People

            ivan.solovev Ivan Solovev
            asperamanca Robert Schimkowitsch
            Vladimir Minenko Vladimir Minenko
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: