Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. [solved]Register function to Javascript window object
QtWS25 Last Chance

[solved]Register function to Javascript window object

Scheduled Pinned Locked Moved QtWebEngine
10 Posts 2 Posters 6.0k 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.
  • H Offline
    H Offline
    Hachaso
    wrote on last edited by
    #1

    Hi,

    I'm using the new WebEngine to play around and learn.
    I've been trying to find some similar methods found using QT WebKit: addtojavascriptwindowobject

    I found that using QT WebEngine I have to use the QWebChannel to register functions to the Javascript window object. If this is correct it takes me to the following question.

    I've installed QT 5.4.0 on my computer. I noticed that qwebchannel.js is not found in the SDK installed on my computer. I found it on the Git source.

    If I have a QT native desktop application with a QWebEnginePage and QWebEngineView. What do I need to be able to register functions on the Javascript window object?

    My desktop application when running navigates automatically to a http page that I have created. So I have access to the content connected to the QWebEngineView.

    Please explain what steps to take so I can make this work?

    Thanks

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      bq. I’ve installed QT 5.4.0 on my computer. I noticed that qwebchannel.js is not found in the SDK installed on my computer.

      On my system it is at path <QtDir>/5.4/Src/qtwebchannel/src/webchannel/. See if you have it there.

      For the implementation of QWebchannel I would suggest you to follow "this":http://doc.qt.io/qt-5/qtwebchannel-standalone-example.html example. It is self-explanatory.
      Check out the index.html in it for what you have to add in your http page.

      157

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Hachaso
        wrote on last edited by
        #3

        I have had a look at that example. What I don't understand is if qwebchannel.js is something that has to be included in every project using QWebChannel?

        The version of Qt 5.4 that I have installed on my Windows computer is.
        qt-opensource-windows-x86-msvc2013_64_opengl-5.4.0.exe

        There is no ./src/qwebchannel/src/webchannel folder.

        I guess that the folder you refer to is something found in the Git repository source code.

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          bq. What I don’t understand is if qwebchannel.js is something that has to be included in every project using QWebChannel?

          Not compulsory. You can load it in HTML page from a other location too, like network or any other physical path on your machine. But as far as I understand qwebchannel.js is necesssary.

          bq. There is no ./src/qwebchannel/src/webchannel folder.

          May be you have not installed the source components during installation of Qt. Anyway both files should be the same.

          157

          1 Reply Last reply
          0
          • H Offline
            H Offline
            Hachaso
            wrote on last edited by
            #5

            Maybe you can help me get the StandAlone example up and running.

            I've downloaded the qwebchannel.js file and added it to the path so the StandAlone project can find it. It Build and starts up. I can see the dialog but communication with the HTML file using websocket doesn't seem to work.
            Do I need some magical step to get the communication up and running ?

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              Did it invoke the browser ?

              157

              1 Reply Last reply
              0
              • H Offline
                H Offline
                Hachaso
                wrote on last edited by
                #7

                It invokes Google Chrome with this file in the navigation field.

                file:///C:/Qt/Qt5.4.0/Examples/Qt-5.4/webchannel/build-standalone-Desktop_Qt_5_4_0_MSVC2013_OpenGL_64bit-Debug/index.html

                I can see an input box field but it's empty with no text.

                1 Reply Last reply
                0
                • p3c0P Offline
                  p3c0P Offline
                  p3c0
                  Moderators
                  wrote on last edited by
                  #8

                  Ok. Now keeping the Qt Dialog window open, goto the browser and just append ?webChannelBaseUrl=ws://127.0.0.1:12345 to file:///C:/Qt/Qt5.4.0/Examples/Qt-5.4/webchannel/build-standalone-Desktop_Qt_5_4_0_MSVC2013_OpenGL_64bit-Debug/index.html and reload.

                  157

                  1 Reply Last reply
                  0
                  • H Offline
                    H Offline
                    Hachaso
                    wrote on last edited by
                    #9

                    That worked like a charm. Thanks a lot. That was the missing piece. :-)

                    1 Reply Last reply
                    0
                    • p3c0P Offline
                      p3c0P Offline
                      p3c0
                      Moderators
                      wrote on last edited by
                      #10

                      Glad that it worked :)
                      Please mark it as solved by editing the post title and prepend [solved].

                      157

                      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