Migrating from QtWebKit to QtWebEngine, using QWebChannel.
I have an invokable function that sends a QVariant Object to the Javascript, which is seen as a JSON object. So a QString
becomes a string
, a QInt
an int
, etc.
Using QtWebKit without QWebChannel, a QByteArray was seen as a Uint8ClampedArray
, but is now directly transformed to a string
using UTF-8 (Which my QByteArray is not :( )
Did I do something wrong ? What should I do ?
Here is the relevant code part :
//Qt Window class signal to javascript
void MyWindow::uplink(Response msg)
{
emit _nativeToJs(msg->toJson());
}
//Response class toJson() method
QVariantMap Response::toJson() const
{
QVariantMap map;
map["id"] = m_id; //qulonglong
map["src"] = QString(m_src);
map["dst"] = QString(m_dst);
map["status"] = m_status; //qint16
map["result"] = m_result; //QVariant, can be a map of string, arrays, etc
return map;
}
//Javascript
var foo;
new QWebChannel(qt.webChannelTransport, function(channel) {
//we connect the signal
channel.objects.foo._nativeToJs.connect(function(msg){
//msg is now a JSON object
});
});
msg.result
should contains a clamped array (msgpack data) that I later decode. Now I have an ugly string
of not UTF-8 chars interpreted as UTF-8, which I can't do anything with.