diff options
author | Dominik Holland <dominik.holland@pelagicore.com> | 2018-09-06 11:47:14 +0200 |
---|---|---|
committer | Dominik Holland <dominik.holland@pelagicore.com> | 2018-09-14 13:01:46 +0000 |
commit | d87d7161a9267c33990a8fb172310e4ade291c13 (patch) | |
tree | e8ece1e05cdd00ab5ab4054d17e63276041e202c | |
parent | e54f439758007f2212442a90a3c44333b5a60268 (diff) | |
download | qtivi-d87d7161a9267c33990a8fb172310e4ade291c13.tar.gz |
Make it possible to set the result for QIviPendingReply<void> from QML
The type check prevented this before. Now the type is ignored for
QIviPendingReply<void> when used from QML.
Change-Id: Iabdea29ba8d7af28f1b3e273260f0af013609253
Reviewed-by: Robert Griebl <robert.griebl@pelagicore.com>
-rw-r--r-- | src/ivicore/qivipendingreply.cpp | 4 | ||||
-rw-r--r-- | tests/auto/core/qivipendingreply/qivipendingreply.pro | 2 | ||||
-rw-r--r-- | tests/auto/core/qivipendingreply/tst_qivipendingreply.cpp | 36 |
3 files changed, 39 insertions, 3 deletions
diff --git a/src/ivicore/qivipendingreply.cpp b/src/ivicore/qivipendingreply.cpp index e7bcde9..f6368bb 100644 --- a/src/ivicore/qivipendingreply.cpp +++ b/src/ivicore/qivipendingreply.cpp @@ -454,8 +454,8 @@ void QIviPendingReplyWatcher::setSuccess(const QVariant &value) return; } - //no type checking needed when we expect a QVariant - if (d->m_type == qMetaTypeId<QVariant>()) { + //no type checking needed when we expect a QVariant or void + if (d->m_type == qMetaTypeId<QVariant>() || d->m_type == qMetaTypeId<void>()) { d->setSuccess(value); return; } diff --git a/tests/auto/core/qivipendingreply/qivipendingreply.pro b/tests/auto/core/qivipendingreply/qivipendingreply.pro index bc9eea9..36e0a42 100644 --- a/tests/auto/core/qivipendingreply/qivipendingreply.pro +++ b/tests/auto/core/qivipendingreply/qivipendingreply.pro @@ -1,6 +1,6 @@ QT += testlib ivicore qml -TARGET = tst_qiviasyncreply +TARGET = tst_qivipendingreply QMAKE_PROJECT_NAME = $$TARGET CONFIG += testcase diff --git a/tests/auto/core/qivipendingreply/tst_qivipendingreply.cpp b/tests/auto/core/qivipendingreply/tst_qivipendingreply.cpp index 31bbcda..a3e36c6 100644 --- a/tests/auto/core/qivipendingreply/tst_qivipendingreply.cpp +++ b/tests/auto/core/qivipendingreply/tst_qivipendingreply.cpp @@ -142,6 +142,7 @@ private Q_SLOTS: void initTestCase(); void testSuccess(); void testSuccess_qml(); + void testSuccessFromQml(); void testConversion_qml(); void testFailed(); void testFailed_qml(); @@ -331,6 +332,41 @@ void tst_QIviPendingReply::testSuccess_qml() testQml<TestGadget>(&testObject, "test_TestGadget(testObject.createGadget('FOO', 5))", false, TestGadget("FOO", 5)); } +void tst_QIviPendingReply::testSuccessFromQml() +{ + // Instead of using the PendingReply in QML and react on the result using then() + // we test here to set the result using the setSuccess function + + QIviPendingReply<void> voidReply; + QIviPendingReply<int> intReply; + + QVERIFY(!voidReply.isResultAvailable()); + QVERIFY(!intReply.isResultAvailable()); + + QQmlEngine engine; + engine.rootContext()->setContextProperty("voidReply", QVariant::fromValue(QIviPendingReplyBase(voidReply))); + engine.rootContext()->setContextProperty("intReply", QVariant::fromValue(QIviPendingReplyBase(intReply))); + + QByteArray qml ("import QtQuick 2.0; \n\ + QtObject { \n\ + Component.onCompleted: { \n\ + voidReply.setSuccess(true) \n\ + intReply.setSuccess(5) \n\ + }\n\ + }"); + QQmlComponent component(&engine); + component.setData(qml, QUrl()); + QScopedPointer<QObject> obj(component.create()); + QVERIFY2(obj, qPrintable(component.errorString())); + + QVERIFY(voidReply.isResultAvailable()); + QVERIFY(voidReply.isSuccessful()); + + QVERIFY(intReply.isResultAvailable()); + QVERIFY(intReply.isSuccessful()); + QCOMPARE(intReply.value(), 5); +} + void tst_QIviPendingReply::testConversion_qml() { TestObject testObject; |