Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.5.0
-
None
Description
I have the following code in an HTML file (loaded into a QWebEnginePage):
function runTest() { var _ = new QWebChannel(qt.webChannelTransport, function(channel) { var obj = { "testObject": "yes" }; channel.objects.proxy.logVariant(obj); channel.objects.proxy.logJSONValue(obj); channel.objects.proxy.logJSONObject(obj); channel.objects.proxy.logString(JSON.stringify(obj)); }); document.write("Loaded!"); }
On the C++ side the methods are defined as:
Q_INVOKABLE void logVariant(const QVariant &val); Q_INVOKABLE void logJSONValue(const QJsonValue &val); Q_INVOKABLE void logJSONObject(const QJsonObject &val); Q_INVOKABLE void logString(const QString &val); void WebProxy::logVariant(const QVariant &val) { qDebug() << "VARIANT VAL:" << val.toJsonValue(); qDebug() << "VARIANT OBJ:" << val.toJsonObject(); } void WebProxy::logJSONValue(const QJsonValue &val) { qDebug() << "JSON VALUE:" << val; } void WebProxy::logJSONObject(const QJsonObject &val) { qDebug() << "JSON OBJECT:" << val; } void WebProxy::logString(const QString &val) { qDebug() << "STRING:" << val; }
(you can find the full compilable project here: https://github.com/ileonte/qwebchantest)
When ran the program outputs the following:
VARIANT VAL: QJsonValue(null) VARIANT OBJ: QJsonObject() Could not convert argument QJsonValue(object, QJsonObject({"testObject":"yes"})) to target type "QJsonValue" . Could not convert argument QJsonValue(object, QJsonObject({"testObject":"yes"})) to target type "QJsonObject" . STRING: "{\"testObject\":\"yes\"}"
I've confirmed this behavior on both Linux (gcc) and Windows (MSVC2013) both 64bit.