PDA

View Full Version : Passing binary data between Qt classes and JS through Qt Webkit bridge



platon
24th April 2014, 21:54
Hi all,

My web application needs to have access to sockets (WebSockets is not an option in my case). The application will work in Webkit browser so I decided to write a plugin for webkit browser using Qt Webkit bridge technology. It seems that QTcpSocket should absolutely suite my needs.

But unfortunately after reading through the documentation on Qt Webkit bridge I didn't find any data type which will be suitable for passing binary data between plugin and JS application. In the documentation only a few data types which supposed to be automatically converted between Qt and JS are described.

The problem is that e.g. QIODevice::write method takes either char* or QByteArray.

After my investigation I can make a conclusion that the only way to pass binary data between Qt and JS is to pack it in string. But probably there are better ways for that.

Any suggestions are welcome. Thanks.

platon
25th April 2014, 16:37
It seems that starting from Qt Webkit 5 they added support of Uint8Array in bridge. If I'm looking into a proper place (qtwebkit/Source/WebCore/bridge/qt/qt_runtime.cpp). But anyway I still can't figure out how to properly pass such type of data between Qt and JS.

platon
28th April 2014, 15:14
The problem resolved. It turned out that in Qt webkit 5.x QByteArray is mapped to Uint8ClampedArray and vise versa when passing through Qt webkit bridge. But I think the documentation for Qt webkit bridge should be updated because I had to read sources to find it out which took me a lot of time.

anda_skoa
28th April 2014, 17:21
I think it is possible to file a bug report against the documentation.

You could of course also contribute to Qt documentation yourself :)

Cheers,
_