对象暴露给Javascript

对象暴露给Javascript

本文介绍了使用QtWebEngine在Qt中将C ++对象暴露给Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用QtWebkit,可以通过 QWebFrame :: addToJavaScriptWindowObject 将C ++对象公开给Javascript,如

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

使用QtWebEngine可以在Qt 5.4中完成同样的事情吗? / p>

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

推荐答案

使用QWebEngine无法直接将C ++对象导出为HTML / JS。

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

相反,新推出的 QWebChannel 提供了HTML / JS和C ++之间的桥梁。请查看,尤其是示例。在今年的Qt开发者日期间,还有一个关于QWebChannel的非常好的介绍性讨论,这也可能是您感兴趣的。会谈的视频将在几周内上线。

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.

这篇关于使用QtWebEngine在Qt中将C ++对象暴露给Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 01:47