Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Transport for QWebEnginePage::setWebChannel()

    General and Desktop
    qt webengine qwebengine qwebchannel qwe qwebchannel
    3
    3
    2672
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      Matty last edited by

      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 (http://doc.qt.io/qt-5/qwebenginepage.html#setWebChannel) mentions that qt.webChannelTransport should be available in the javascript context, but I don't see where that is established in qwebchannel.js (https://github.com/qtproject/qtwebchannel/blob/dev/src/webchannel/qwebchannel.js). I've seen the WebChannel examples (http://doc.qt.io/qt-5/qtwebchannel-examples.html) 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()->setWebChannel(channel);
      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).

      ? 1 Reply Last reply Reply Quote 0
      • ?
        A Former User @Matty last edited by

        @Matty

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

        1 Reply Last reply Reply Quote 0
        • V
          VernJensen last edited by VernJensen

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • First post
            Last post