Nominate our 2022 Qt Champions!

Transport for QWebEnginePage::setWebChannel()

  • I'm using the QT WebEngine framework to display web pages. I'm injecting javascript into a page when it loads, and want to allow the javascript to be able to access and QT object. Apparently, to do this a QWebChannel must exist that establishes some IPC between chromium (the javascript) and the rest of my C++/QT project. I came across the QWebEnginePage::setWebChannel (QWebChannel *channel) function, however I can't find any examples of its use. The documentation ( mentions that qt.webChannelTransport should be available in the javascript context, but I don't see where that is established in qwebchannel.js ( I've seen the WebChannel examples ( and would like to avoid WebSockets if possible.

    Are there examples of a project that sets up a web channel in this way? Below is how I tried to implement the web channel.

    Whenever a page loads I establish a channel and inject the javascript in C++:

    QWebChannel *channel = new QWebChannel();
    channel->registerObject(QStringLiteral("jshelper"), helper);

    view->page()->runJavaScript(qwebjs); //this is qwebchannel.js
    view->page()->runJavaScript(myfunction); //function that calls QT object (jshelper)

    In Javascript:
    new QWebChannel(qt.webChannelTransport, function(channel) { ... });

    Which results in the channel not being connected properly (assuming this is because of qt.webChannelTransport, as it was working when I was using WebSockets).

  • @Matty

    I'm running into this now. Were you able to find a solution?

  • This post is deleted!