我試圖讓QML(main.qml)使用 url: "file:///../../htmlfiles/index.html"
加載本地HTML文件index.html,但它不起作用。在QML Webview中使用相對URL
你能幫忙嗎?
我試圖讓QML(main.qml)使用 url: "file:///../../htmlfiles/index.html"
加載本地HTML文件index.html,但它不起作用。在QML Webview中使用相對URL
你能幫忙嗎?
我結束了使用setContextProperty()
傳遞qApp->applicationDirPath()
從C++到QML和使用url: "file:///" + applicationDirPath + "/htmlfiles/index.html"
來解決該問題。
嘗試沒有file:///
:
WebView {
url: "../../htmlfiles/index.html"
// [...]
}
有做簡單的方法是:
WebView {
id: translationsList
anchors.fill: parent
url: "qrc:/about.html"
}
正如Radon在評論中提出的部分,我認爲這是行不通的。 「@pshah:如果QML文件被編譯到程序二進制文件中,並且HTML文件位於二進制文件之外,則它不能被相對路徑引用,因爲這些文件位於兩個不同的」文件系統「中。 – pshah 2011-09-02 04:08:12
嘗試: =文件名 「的/ etc /問題」; url = Qt.resolvedUrl(filename);
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
}
}
這對我有用!
+1:就是這麼做的方法 – funkybro 2011-06-05 07:45:42
'在Qt 5中'engine.rootContext() - > setContextProperty(「workingDirectory」,QUrl :: fromLocalFile(app.applicationDirPath()));' – Timmmm 2014-11-17 14:37:57