I'd like to share my knowledge on this process since it does not seem to be trivial and had to spend some time to figure it out. Hope this will be a useful manual.
The problem:
There is a QT application, that sends large amount of data to be plot using PlotlyJS using QWebChannel. The data contains about 20 million datapoints. After some investigation it turned out that the bottleneck is the QWebChannel
data transfer. One possible solution I figured is to compress the data before putting on the channel. The biggest issue I faced was converting the inflated data back to json in a fast manner and how to use js pako zlib compressor to inflate.
I always received
Uncaught unknown compression method
error after various modifications.
The solution I came up with, can be seen in the answer section.
The solution:
Note: This code does not contain the whole setup of web channel, but only the handling of the data between QT and JS.
QT C++
The important thing is that js
pako.inflate()
does not understand the header generated byqCompress
hence theUnknown compression method error
. The header contains four bytes, that at least in my case were 0-s. Trimming them fixes the error.Don't forget to set your data you want to share with
QWebChannel
asQ_PROPERTY
JS Vanilla
Edit:
Formerly used simple loop to convert binarray to string:
is replaced with a more efficient method using FileReader
Conclusion:
Besides fixing the errors this code allowed me to plot the data in about 10 seconds instead of 30 min+. I also noticed that the performance still drops quite a bit if I double the cell count because of the
binArrayToString
mapping, so it is still the bottleneck.References:
Uint8Array to string in Javascript
How to zlib compress a QByteArray?
How to use pako.js javascript? Pako is not defined