From 90d9a86c2e762c9426d0facbd54ed5dbff574ecd Mon Sep 17 00:00:00 2001 From: Arno Rehn Date: Fri, 9 Jul 2021 16:22:18 +0200 Subject: QMetaType: Support converting any QFuture to QFuture QMetaType now implicitly knows how to convert any QFuture to QFuture without needing to manually register a converter function. QtWebChannel will make use of this to transparently support QFuture return types. [ChangeLog][QtCore][QMetaType] QMetaType now supports converting any QFuture to QFuture. Task-number: QTBUG-92903 Change-Id: Ied7e71be37c346cc3d2c274ffb0d91a6821ab4d4 Reviewed-by: Fabian Kosmale --- tests/auto/corelib/thread/qfuture/tst_qfuture.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests/auto/corelib/thread') diff --git a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp index 8eadaee62a..af83ee3b95 100644 --- a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp +++ b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp @@ -164,6 +164,7 @@ private slots: void createReadyFutures(); void getFutureInterface(); + void convertQMetaType(); private: using size_type = std::vector::size_type; @@ -3532,5 +3533,22 @@ void tst_QFuture::getFutureInterface() QCOMPARE(interface.resultCount(), 1); } +void tst_QFuture::convertQMetaType() +{ + const auto intType = QMetaType::fromType>(); + const auto voidType = QMetaType::fromType>(); + + QVERIFY(QMetaType::canConvert(intType, voidType)); + + const int val = 42; + QFuture f = QtFuture::makeReadyFuture(val); + auto variant = QVariant::fromValue(f); + QVERIFY(variant.convert(voidType)); + + const auto voidFuture = variant.value>(); + QVERIFY(voidFuture.isValid()); + QVERIFY(voidFuture.isFinished()); +} + QTEST_MAIN(tst_QFuture) #include "tst_qfuture.moc" -- cgit v1.2.3