QML WebView无法运行JavaScript

时间:2019-07-17 15:40:05

标签: javascript qt webview qml

所以我尝试在Windows 10(Qt 5.13)上运行以下代码:

import QtQuick 2.13
import QtQuick.Window 2.13
import QtQuick.Controls 2.12
import QtWebView 1.1

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    WebView{
        id: webView
        anchors{
            top: button.bottom
            bottom: parent.bottom
            left: parent.left
            right: parent.right
        }

        url: "http://google.com"
    }
    Button{
        id: button
        text: "Click me"
        onClicked: {
            console.debug("Running javascript")
            webView.runJavaScript("document.title", function(result) { console.log(result); });
        }
    }
}

当我单击按钮时,我得到以下信息:

qt.winrtrunner.app: The WinRT WebView only supports calling global functions, so please make your call in the form myFunction(a, b, c). Also note that only string arguments can be passed.

那是什么意思?控制台为什么不显示网站标题?也有人可以为我澄清here中记录的WebView::runJavascript(script, variant callback)中的“回调”功能是什么吗?

0 个答案:

没有答案