Expose C++ object to Javascript in Qt with QtWebEngine

China☆狼群 提交于 2019-12-23 08:46:27

问题


With QtWebkit it is possible to expose C++ objects to Javascript via QWebFrame::addToJavaScriptWindowObject as described in https://stackoverflow.com/a/20685002/595937

Can the same thing be accomplished in Qt 5.4 using QtWebEngine?


回答1:


Exporting C++ objects to HTML/JS is not directly possible with QWebEngine.

Instead, the newly introduced QWebChannel provides a bridge between HTML/JS and C++. Have a look at the documentation, especially at the examples. There was also a quite good introductory talk about QWebChannel at this year's Qt Developer Days, which might also be of interest to you. The videos of the talks will go online in a few weeks.



来源:https://stackoverflow.com/questions/27512526/expose-c-object-to-javascript-in-qt-with-qtwebengine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!