diff options
author | Arno Rehn <a.rehn@menlosystems.com> | 2019-02-04 15:05:50 +0100 |
---|---|---|
committer | Arno Rehn <a.rehn@menlosystems.com> | 2019-02-04 14:53:24 +0000 |
commit | 38b5128c63ba38303f0587e03536ed546c1f2eca (patch) | |
tree | 40031b4b7e389a79b4728d5d4d64589f101c18f2 | |
parent | 91c92ce0144eb8c0639aef012508e24d8b7e72a5 (diff) | |
download | qtwebchannel-38b5128c63ba38303f0587e03536ed546c1f2eca.tar.gz |
Correctly unwrap registered objects
Previously, only implicitly wrapped objects have been successfully
unwrapped. "Officially" registered objects were not, and thus could not
be passed to properties or as method arguments.
Change-Id: I6b8644ed3be8db3a66c2c1d5bc167fc33a0b4165
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
-rw-r--r-- | src/webchannel/qmetaobjectpublisher.cpp | 3 | ||||
-rw-r--r-- | tests/auto/webchannel/tst_webchannel.cpp | 19 | ||||
-rw-r--r-- | tests/auto/webchannel/tst_webchannel.h | 1 |
3 files changed, 23 insertions, 0 deletions
diff --git a/src/webchannel/qmetaobjectpublisher.cpp b/src/webchannel/qmetaobjectpublisher.cpp index 6ea3480..b34b39e 100644 --- a/src/webchannel/qmetaobjectpublisher.cpp +++ b/src/webchannel/qmetaobjectpublisher.cpp @@ -491,6 +491,9 @@ QObject *QMetaObjectPublisher::unwrapObject(const QString &objectId) const ObjectInfo objectInfo = wrappedObjects.value(objectId); if (objectInfo.object && !objectInfo.classinfo.isEmpty()) return objectInfo.object; + QObject *object = registeredObjects.value(objectId); + if (object) + return object; } qWarning() << "No wrapped object" << objectId; diff --git a/tests/auto/webchannel/tst_webchannel.cpp b/tests/auto/webchannel/tst_webchannel.cpp index 6764204..e46d097 100644 --- a/tests/auto/webchannel/tst_webchannel.cpp +++ b/tests/auto/webchannel/tst_webchannel.cpp @@ -708,6 +708,25 @@ void TestWebChannel::testWrapRegisteredObject() QCOMPARE(obj.objectName(), returnedId); } +void TestWebChannel::testUnwrapObject() +{ + QWebChannel channel; + + { + TestObject obj; + obj.setObjectName("testObject"); + channel.registerObject(obj.objectName(), &obj); + QObject *unwrapped = channel.d_func()->publisher->unwrapObject(obj.objectName()); + QCOMPARE(unwrapped, &obj); + } + { + TestObject obj; + QJsonObject objectInfo = channel.d_func()->publisher->wrapResult(QVariant::fromValue(&obj), m_dummyTransport).toObject(); + QObject *unwrapped = channel.d_func()->publisher->unwrapObject(objectInfo["id"].toString()); + QCOMPARE(unwrapped, &obj); + } +} + void TestWebChannel::testRemoveUnusedTransports() { QWebChannel channel; diff --git a/tests/auto/webchannel/tst_webchannel.h b/tests/auto/webchannel/tst_webchannel.h index 386f314..40e6fba 100644 --- a/tests/auto/webchannel/tst_webchannel.h +++ b/tests/auto/webchannel/tst_webchannel.h @@ -311,6 +311,7 @@ private slots: void testSetPropertyConversion(); void testDisconnect(); void testWrapRegisteredObject(); + void testUnwrapObject(); void testRemoveUnusedTransports(); void testPassWrappedObjectBack(); void testWrapValues(); |