在QML Webview中使用相对URL

时间:2011-05-24 19:49:49

标签: url webview relative qml

我正在尝试使用QML(main.qml)加载本地HTML文件index.html         url: "file:///../../htmlfiles/index.html" 但它不起作用。

你能帮忙吗?

5 个答案:

答案 0 :(得分:5)

我最终使用qApp->applicationDirPath()setContextProperty()从c ++传递到QML并使用url: "file:///" + applicationDirPath + "/htmlfiles/index.html"来解决问题。

答案 1 :(得分:3)

WebView {
        url: Qt.resolvedUrl( "html/index.html" )
        x: 0
        y: 0
        smooth: false
        anchors {
            top: window.top
            bottom: window.bottom
            left: window.left
            right: window.right
        }
    }

这对我有用!

答案 2 :(得分:2)

尝试不使用file:///

WebView {
    url: "../../htmlfiles/index.html"
    // [...]
}

答案 3 :(得分:1)

有更简单的方法:

WebView {
        id: translationsList
        anchors.fill: parent
        url: "qrc:/about.html"
        }

答案 4 :(得分:0)

尝试:        文件名= “/等/问题”;        url = Qt.resolvedUrl(filename);

相关问题