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

来源:互联网 发布:淘宝关键词搜索量查询 编辑:程序博客网 时间:2024/06/05 14:38

示例来源于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

把这个属性设置成真!

 

 

 

 

 

 

原创粉丝点击