当前位置: 代码迷 >> 综合 >> QML中webview元素的javaScriptWindowObjects的使用示例
  详细解决方案

QML中webview元素的javaScriptWindowObjects的使用示例

热度:47   发布时间:2024-01-22 06:22:24.0

示例来源于Qt自己的帮助文档(QML WebView):

 

This example shows how to call into a QML method using a window object.

这个例子显示的是如何使用window对象来调用qml中的方法:

 WebView {
javaScriptWindowObjects: QtObject {
WebView.windowObjectName: "qml"
function qmlCall() {
console.log("This call is in QML!");
}
}
html: "<script>window.qml.qmlCall();</script>"
}

If Javascript is not enabled for the page, then this property does nothing.

当然能够使用js的前提是在webview中允许使用js,设置方法是:

settings.javascriptEnabled : bool

把这个属性设置成真!