diff --git a/src/corelib/thread/qfuture.h b/src/corelib/thread/qfuture.h index 8c04b8c4376..ab08f7861c7 100644 --- a/src/corelib/thread/qfuture.h +++ b/src/corelib/thread/qfuture.h @@ -300,6 +300,8 @@ private: template friend class QFuture; + friend class QFutureInterfaceBase; + template friend class QtPrivate::Continuation; @@ -430,6 +432,12 @@ inline QFuture QFutureInterface::future() return QFuture(this); } +template +QFutureInterfaceBase QFutureInterfaceBase::get(const QFuture &future) +{ + return future.d; +} + Q_DECLARE_SEQUENTIAL_ITERATOR(Future) QT_END_NAMESPACE diff --git a/src/corelib/thread/qfutureinterface.h b/src/corelib/thread/qfutureinterface.h index 6924378bf19..ecc31d6ec35 100644 --- a/src/corelib/thread/qfutureinterface.h +++ b/src/corelib/thread/qfutureinterface.h @@ -177,6 +177,9 @@ public: // ### Qt 7: inline void swap(QFutureInterfaceBase &other) noexcept; + template + static QFutureInterfaceBase get(const QFuture &future); // implemented in qfuture.h + protected: // ### Qt 7: remove const from refT/derefT bool refT() const noexcept; diff --git a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp index eff07ce309d..8eadaee62aa 100644 --- a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp +++ b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp @@ -163,6 +163,8 @@ private slots: void createReadyFutures(); + void getFutureInterface(); + private: using size_type = std::vector::size_type; @@ -3521,5 +3523,14 @@ void tst_QFuture::createReadyFutures() #endif } +void tst_QFuture::getFutureInterface() +{ + const int val = 42; + QFuture f = QtFuture::makeReadyFuture(val); + + auto interface = QFutureInterfaceBase::get(f); + QCOMPARE(interface.resultCount(), 1); +} + QTEST_MAIN(tst_QFuture) #include "tst_qfuture.moc"