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

QFuture continuation segfaults with move only datatypes

    XMLWordPrintable

Details

    • Linux/X11
    • 1f22fc995 (dev), bfcfd2394 (6.5), 4672843ae (6.6)

    Description

      Using QFuture continuations with `unique_ptr` crashes, as in the following example

      #include <memory>
      
      #include <QCoreApplication>
      
      #include <QFuture>
      #include <QPromise>
      #include <QSharedPointer>
      #include <QThread>
      
      int main(int argc, char *argv[]) {
        QCoreApplication a(argc, argv);
      
        QSharedPointer<QPromise<std::unique_ptr<int>>> sharedPromise(
            new QPromise<std::unique_ptr<int>>);
      
        QFuture<std::unique_ptr<int>> future = sharedPromise->future();
      
        QScopedPointer<QThread> thread(QThread::create(
            [](QSharedPointer<QPromise<std::unique_ptr<int>>> sharedPromise) {
              // doing some work
              QThread::sleep(1);
      
              sharedPromise->start();
              sharedPromise->addResult(std::make_unique<int>(1));
              sharedPromise->finish();
            },
            sharedPromise));
      
        thread->start();
      
        future.then([](const std::unique_ptr<int> &value) { qDebug() << *value; });
        QThread::sleep(2);
      }
      
      

      Simply replacing `unique_ptr` with `shared_ptr` fixes the problem.

      Attachments

        Issue Links

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

          Activity

            People

              sonakur Sona Kurazyan
              theartful Ahmed Essam
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews