开发者

Use relative url in QML Webview

I'm trying to get QML (main.qml) to load a local HTML file index.html using url: "file:///../../htmlfiles/index.html" but it doesn't work.

Ca开发者_JS百科n you please help?


I ended up passing qApp->applicationDirPath() from c++ to QML using setContextProperty() and used url: "file:///" + applicationDirPath + "/htmlfiles/index.html" to fix the issue.


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
        }
    }

This works for me!


Try without file:///:

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


There is simpler way to do that:

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


try : filename="/etc/issue"; url = Qt.resolvedUrl( filename );

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜