From 97c876a1353f29ed0129360f013f2529bed69d98 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Wed, 25 May 2016 16:42:01 +0200 Subject: Enable calling C++ functions taking QJson arguments via webchannel. We used to convert the QJsonValue arguments to QVariants, which then failed to call a C++ function which expected on of the three QJson data types, i.e. QJsonValue, QJsonObject or QJsonArray. Instead, we now detect these three cases and manually convert the QJsonValue as needed. [ChangeLog] C++ functions taking arguments of type QJsonValue, QJsonArray or QJsonObject can now be called via the Qt WebChannel. Change-Id: I94e0c8937ca35e2ecd3554f7ddf2d4e5a3328570 Task-number: QTBUG-48198 Reviewed-by: Simon Hausmann --- tests/auto/webchannel/tst_webchannel.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests/auto/webchannel/tst_webchannel.h') diff --git a/tests/auto/webchannel/tst_webchannel.h b/tests/auto/webchannel/tst_webchannel.h index b2a1040..e551458 100644 --- a/tests/auto/webchannel/tst_webchannel.h +++ b/tests/auto/webchannel/tst_webchannel.h @@ -36,6 +36,7 @@ #include #include +#include #include @@ -229,6 +230,9 @@ public: Q_INVOKABLE void setInt(int i); Q_INVOKABLE void setDouble(double d); Q_INVOKABLE void setVariant(const QVariant &v); + Q_INVOKABLE void setJsonValue(const QJsonValue &v); + Q_INVOKABLE void setJsonObject(const QJsonObject &v); + Q_INVOKABLE void setJsonArray(const QJsonArray &v); private slots: void testRegisterObjects(); @@ -252,6 +256,7 @@ private: int m_lastInt; double m_lastDouble; QVariant m_lastVariant; + QJsonValue m_lastJsonValue; }; QT_END_NAMESPACE -- cgit v1.2.1 From bec50124b893c4632829d9806f49f64c4debf936 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Wed, 25 May 2016 18:20:30 +0200 Subject: Fix setting properties of QJson{Value,Array,Object} type. Similar to the previous issue, where these types were not properly converted to QVariant when invoking a method, we manually do the conversion now to get the desired behavior. The culprit is again that QJsonValue::toVariant converts an object e.g. to a QVariantMap, and not to a QVariant containing a QJsonObject. [ChangeLog] QObject properties of type QJsonValue, QJsonArray or QJsonObject can now be set via the Qt WebChannel. Task-number: QTBUG-48198 Change-Id: I5d574b1a5cffd6d6ad9b555f2a3e872b9c3425a7 Reviewed-by: Simon Hausmann --- tests/auto/webchannel/tst_webchannel.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests/auto/webchannel/tst_webchannel.h') diff --git a/tests/auto/webchannel/tst_webchannel.h b/tests/auto/webchannel/tst_webchannel.h index e551458..13294c2 100644 --- a/tests/auto/webchannel/tst_webchannel.h +++ b/tests/auto/webchannel/tst_webchannel.h @@ -37,6 +37,8 @@ #include #include #include +#include +#include #include @@ -223,22 +225,43 @@ class TestWebChannel : public QObject { Q_OBJECT + Q_PROPERTY(int lastInt READ readInt WRITE setInt NOTIFY lastIntChanged); + Q_PROPERTY(double lastDouble READ readDouble WRITE setDouble NOTIFY lastDoubleChanged); + Q_PROPERTY(QVariant lastVariant READ readVariant WRITE setVariant NOTIFY lastVariantChanged); + Q_PROPERTY(QJsonValue lastJsonValue READ readJsonValue WRITE setJsonValue NOTIFY lastJsonValueChanged); + Q_PROPERTY(QJsonObject lastJsonObject READ readJsonObject WRITE setJsonObject NOTIFY lastJsonObjectChanged); + Q_PROPERTY(QJsonArray lastJsonArray READ readJsonArray WRITE setJsonArray NOTIFY lastJsonArrayChanged); public: explicit TestWebChannel(QObject *parent = 0); virtual ~TestWebChannel(); + int readInt() const; Q_INVOKABLE void setInt(int i); + double readDouble() const; Q_INVOKABLE void setDouble(double d); + QVariant readVariant() const; Q_INVOKABLE void setVariant(const QVariant &v); + QJsonValue readJsonValue() const; Q_INVOKABLE void setJsonValue(const QJsonValue &v); + QJsonObject readJsonObject() const; Q_INVOKABLE void setJsonObject(const QJsonObject &v); + QJsonArray readJsonArray() const; Q_INVOKABLE void setJsonArray(const QJsonArray &v); +signals: + void lastIntChanged(); + void lastDoubleChanged(); + void lastVariantChanged(); + void lastJsonValueChanged(); + void lastJsonObjectChanged(); + void lastJsonArrayChanged(); + private slots: void testRegisterObjects(); void testDeregisterObjects(); void testInfoForObject(); void testInvokeMethodConversion(); + void testSetPropertyConversion(); void testDisconnect(); void testWrapRegisteredObject(); void testInfiniteRecursion(); @@ -257,6 +280,8 @@ private: double m_lastDouble; QVariant m_lastVariant; QJsonValue m_lastJsonValue; + QJsonObject m_lastJsonObject; + QJsonArray m_lastJsonArray; }; QT_END_NAMESPACE -- cgit v1.2.1 From f48e8c9711fbeb350ccf70f852ce3732844d4287 Mon Sep 17 00:00:00 2001 From: Kai Dohmen Date: Mon, 11 Apr 2016 19:38:50 +0200 Subject: Make passing objects from website to server possible If you get an object from the server and want to pass it back to the server via a function the id of the object is passed instead of the whole json object. On the server side QMetaObjectPublisher::invokeMethod now looks up the object in QMetaObjectPublisher::wrappedObjects by the passed object-id. Task-number: QTBUG-50075 Change-Id: Id0df2dfaa79bcba12ca48391ae7537ac1a086898 Reviewed-by: Milian Wolff --- tests/auto/webchannel/tst_webchannel.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/auto/webchannel/tst_webchannel.h') diff --git a/tests/auto/webchannel/tst_webchannel.h b/tests/auto/webchannel/tst_webchannel.h index 13294c2..5a9fa11 100644 --- a/tests/auto/webchannel/tst_webchannel.h +++ b/tests/auto/webchannel/tst_webchannel.h @@ -73,11 +73,13 @@ class TestObject : public QObject Q_PROPERTY(int asdf READ asdf NOTIFY asdfChanged) Q_PROPERTY(QString bar READ bar NOTIFY theBarHasChanged) Q_PROPERTY(QObject * objectProperty READ objectProperty WRITE setObjectProperty NOTIFY objectPropertyChanged) + Q_PROPERTY(TestObject * returnedObject READ returnedObject WRITE setReturnedObject NOTIFY returnedObjectChanged) public: explicit TestObject(QObject *parent = 0) : QObject(parent) , mObjectProperty(0) + , mReturnedObject(Q_NULLPTR) { } enum Foo { @@ -94,6 +96,11 @@ public: return mObjectProperty; } + TestObject *returnedObject() const + { + return mReturnedObject; + } + Q_INVOKABLE void method1() {} protected: @@ -108,11 +115,18 @@ signals: void asdfChanged(); void theBarHasChanged(); void objectPropertyChanged(); + void returnedObjectChanged(); public slots: void slot1() {} void slot2(const QString&) {} + void setReturnedObject(TestObject *obj) + { + mReturnedObject = obj; + emit returnedObjectChanged(); + } + void setObjectProperty(QObject *object) { mObjectProperty = object; @@ -127,6 +141,7 @@ private slots: public: QObject *mObjectProperty; + TestObject *mReturnedObject; }; class BenchObject : public QObject @@ -264,6 +279,7 @@ private slots: void testSetPropertyConversion(); void testDisconnect(); void testWrapRegisteredObject(); + void testPassWrappedObjectBack(); void testInfiniteRecursion(); void benchClassInfo(); -- cgit v1.2.1 From e35346cf70598c47a456946327927643910aa277 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Thu, 16 Jun 2016 12:46:42 +0200 Subject: Add test to verify that bools get properly converted. This test passes and seems to indicate that the signal-delivery has an issue, or that the issue lies on the JavaScript side. Change-Id: Ic2436147b3af49d35dc556da57aed3e54408f1f9 Task-number: QTBUG-54074 Reviewed-by: Frederik Gladhorn --- tests/auto/webchannel/tst_webchannel.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests/auto/webchannel/tst_webchannel.h') diff --git a/tests/auto/webchannel/tst_webchannel.h b/tests/auto/webchannel/tst_webchannel.h index 5a9fa11..3469d41 100644 --- a/tests/auto/webchannel/tst_webchannel.h +++ b/tests/auto/webchannel/tst_webchannel.h @@ -241,6 +241,7 @@ class TestWebChannel : public QObject Q_OBJECT Q_PROPERTY(int lastInt READ readInt WRITE setInt NOTIFY lastIntChanged); + Q_PROPERTY(bool lastBool READ readBool WRITE setBool NOTIFY lastBoolChanged); Q_PROPERTY(double lastDouble READ readDouble WRITE setDouble NOTIFY lastDoubleChanged); Q_PROPERTY(QVariant lastVariant READ readVariant WRITE setVariant NOTIFY lastVariantChanged); Q_PROPERTY(QJsonValue lastJsonValue READ readJsonValue WRITE setJsonValue NOTIFY lastJsonValueChanged); @@ -252,6 +253,8 @@ public: int readInt() const; Q_INVOKABLE void setInt(int i); + bool readBool() const; + Q_INVOKABLE void setBool(bool b); double readDouble() const; Q_INVOKABLE void setDouble(double d); QVariant readVariant() const; @@ -265,6 +268,7 @@ public: signals: void lastIntChanged(); + void lastBoolChanged(); void lastDoubleChanged(); void lastVariantChanged(); void lastJsonValueChanged(); @@ -293,6 +297,7 @@ private: DummyTransport *m_dummyTransport; int m_lastInt; + bool m_lastBool; double m_lastDouble; QVariant m_lastVariant; QJsonValue m_lastJsonValue; -- cgit v1.2.1