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

QFuture::onCanceled is not called when promise is deleted

    XMLWordPrintable

Details

    • 3
    • bf3fc5c95c (qt/qtbase/dev) bf3fc5c95c (qt/tqtc-qtbase/dev) 841f04f309 (qt/qtbase/6.4) 841f04f309 (qt/tqtc-qtbase/6.4) 98b9b719c7 (qt/qtbase/6.3) 98b9b719c7 (qt/tqtc-qtbase/6.3)
    • Team A Foundation Sprint 59

    Description

      Given the following code:

      QFuture<int> getInteger()
      {
          auto promise = QSharedPointer<QPromise<int>>::create();
          QTimer::singleShot(1000, qApp, [promise] () mutable {
              promise->start();
              QTimer::singleShot(1000, qApp, [] () { qApp->quit(); });
          });
          return promise->future();
      }
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
      
          auto future = getInteger();
      
          future
              .onCanceled([]{
                  qDebug() << "Canceled";
                  return  -1;
              });
      
          QFutureWatcher<int> watcher;
          watcher.setFuture(future);
      
          QObject::connect(&watcher, &QFutureWatcher<int>::canceled, []{ qDebug() << "watcher canceled"; });
          QObject::connect(&watcher, &QFutureWatcher<int>::finished, []{ qDebug() << "watcher finished"; });
          QObject::connect(&watcher, &QFutureWatcher<int>::started, []{ qDebug() << "watcher started"; });
      
          return a.exec();
      }

      WIth Qt 6.2.4 and Qt 6.1.3 we have the correct output:

      Canceled
      watcher started
      watcher canceled
      watcher finished
      

      However, with Qt 6.3.0, or the latest 6.4 snapshot, the onCanceled handler in never called:

      watcher started
      watcher canceled
      watcher finished
      

      Attachments

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

        Activity

          People

            sonakur Sona Kurazyan
            bterrier Benjamin Terrier
            Vladimir Minenko Vladimir Minenko
            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