2

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

你能帮忙吗?

4

5 回答 5

5

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

于 2011-05-26T15:17:12.743 回答
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
        }
    }

这对我有用!

于 2012-06-13T20:12:32.937 回答
2

尝试不使用file:///

WebView {
    url: "../../htmlfiles/index.html"
    // [...]
}
于 2011-05-25T08:08:21.447 回答
1

有更简单的方法可以做到这一点:

WebView {
        id: translationsList
        anchors.fill: parent
        url: "qrc:/about.html"
        }
于 2011-09-01T19:40:05.113 回答
0

尝试:文件名=“/etc/issue”;url = Qt.resolvedUrl( 文件名 );

于 2012-02-10T02:53:20.603 回答