Add QFutureInterfaceBase::get() to retrieve internals of QFuture
For generic interop with other parts of Qt, we need to be able to extract the type-erased internal storage of QFuture<T>. In particular, QtWebChannel needs this to transparently support QFuture<T> as a method return type. Task-number: QTBUG-92903 Change-Id: I763f054656b8810d58720262d364baf42c47eb37 Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
This commit is contained in:
parent
82bc752497
commit
1f2d756d92
@ -300,6 +300,8 @@ private:
|
|||||||
template<class U>
|
template<class U>
|
||||||
friend class QFuture;
|
friend class QFuture;
|
||||||
|
|
||||||
|
friend class QFutureInterfaceBase;
|
||||||
|
|
||||||
template<class Function, class ResultType, class ParentResultType>
|
template<class Function, class ResultType, class ParentResultType>
|
||||||
friend class QtPrivate::Continuation;
|
friend class QtPrivate::Continuation;
|
||||||
|
|
||||||
@ -430,6 +432,12 @@ inline QFuture<void> QFutureInterface<void>::future()
|
|||||||
return QFuture<void>(this);
|
return QFuture<void>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
QFutureInterfaceBase QFutureInterfaceBase::get(const QFuture<T> &future)
|
||||||
|
{
|
||||||
|
return future.d;
|
||||||
|
}
|
||||||
|
|
||||||
Q_DECLARE_SEQUENTIAL_ITERATOR(Future)
|
Q_DECLARE_SEQUENTIAL_ITERATOR(Future)
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -177,6 +177,9 @@ public:
|
|||||||
// ### Qt 7: inline
|
// ### Qt 7: inline
|
||||||
void swap(QFutureInterfaceBase &other) noexcept;
|
void swap(QFutureInterfaceBase &other) noexcept;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static QFutureInterfaceBase get(const QFuture<T> &future); // implemented in qfuture.h
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// ### Qt 7: remove const from refT/derefT
|
// ### Qt 7: remove const from refT/derefT
|
||||||
bool refT() const noexcept;
|
bool refT() const noexcept;
|
||||||
|
@ -163,6 +163,8 @@ private slots:
|
|||||||
|
|
||||||
void createReadyFutures();
|
void createReadyFutures();
|
||||||
|
|
||||||
|
void getFutureInterface();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using size_type = std::vector<int>::size_type;
|
using size_type = std::vector<int>::size_type;
|
||||||
|
|
||||||
@ -3521,5 +3523,14 @@ void tst_QFuture::createReadyFutures()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QFuture::getFutureInterface()
|
||||||
|
{
|
||||||
|
const int val = 42;
|
||||||
|
QFuture<int> f = QtFuture::makeReadyFuture(val);
|
||||||
|
|
||||||
|
auto interface = QFutureInterfaceBase::get(f);
|
||||||
|
QCOMPARE(interface.resultCount(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QFuture)
|
QTEST_MAIN(tst_QFuture)
|
||||||
#include "tst_qfuture.moc"
|
#include "tst_qfuture.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user