Solved QWebEngine communcation from a Websocket on a WebWorker
-
I'm using QWebEngineView in conjuction with QWebChannel to communicate between JS to C++. I'm trying to figure out a way to communicate directly from a WebWorker to the under lying QWebChannel. I really don't want to post a message to the main JS context to then post a message to the QWebChannel. Is there a way to bypass the middle man?
I did try using a WebSocket and QWebSocketServer, but the websocket never seems to finish connecting.
-
@steno If so, then implement the logic that is inside window.onload from the official example: https://code.qt.io/cgit/qt/qtwebchannel.git/tree/examples/webchannel/chatclient-html/chatclient.html?h=5.15#n21 in the WebWorker.
-
@steno QtWebChannel is simply a code that sends information through websockets where objects are encoded and decoded. Since I don't know much about WebWorker it couldn't help you much but if you can run a websocket in a WebWorker then you can easily start qwebchannel in the WebWorker. Can websockets run on WebWorker?
-
@eyllanesc Yes WebSockets in Webworkers are supported in Chromium 89 which Qt 5.15.5 is targeting.
-
@steno If so, then implement the logic that is inside window.onload from the official example: https://code.qt.io/cgit/qt/qtwebchannel.git/tree/examples/webchannel/chatclient-html/chatclient.html?h=5.15#n21 in the WebWorker.