[solved]Register function to Javascript window object
-
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: addtojavascriptwindowobjectI 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
-
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. -
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.exeThere is no ./src/qwebchannel/src/webchannel folder.
I guess that the folder you refer to is something found in the Git repository source code.
-
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.
-
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 ? -
Did it invoke the browser ?
-
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.
-
Glad that it worked :)
Please mark it as solved by editing the post title and prepend [solved].