path: root/tests/auto/webchannel/tst_webchannel.h
diff options
authorMilian Wolff <>2016-05-25 18:20:30 +0200
committerMilian Wolff <>2016-05-26 09:56:54 +0000
commitbec50124b893c4632829d9806f49f64c4debf936 (patch)
tree90986763724e26b5f0b5df993dda06b3f2086081 /tests/auto/webchannel/tst_webchannel.h
parent97c876a1353f29ed0129360f013f2529bed69d98 (diff)
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 <>
Diffstat (limited to 'tests/auto/webchannel/tst_webchannel.h')
1 files changed, 25 insertions, 0 deletions
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 <QObject>
#include <QVariant>
#include <QJsonValue>
+#include <QJsonObject>
+#include <QJsonArray>
#include <QtWebChannel/QWebChannelAbstractTransport>
@@ -223,22 +225,43 @@ class TestWebChannel : public QObject
+ 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);
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);
+ 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;