Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Transport for QWebEnginePage::setWebChannel()
QtWS25 Last Chance

Transport for QWebEnginePage::setWebChannel()

Scheduled Pinned Locked Moved General and Desktop
qt webengineqwebengineqwebchannel qweqwebchannel
3 Posts 3 Posters 3.1k Views
  • 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 Offline
    M Offline
    Matty
    wrote on 10 Aug 2015, 19:31 last edited by
    #1

    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 27 Nov 2015, 00:17
    0
    • M Matty
      10 Aug 2015, 19:31

      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).

      ? Offline
      ? Offline
      A Former User
      wrote on 27 Nov 2015, 00:17 last edited by
      #2

      @Matty

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

      1 Reply Last reply
      0
      • V Offline
        V Offline
        VernJensen
        wrote on 18 Feb 2016, 03:33 last edited by VernJensen
        #3
        This post is deleted!
        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved