我正在尝试让 QML (main.qml) 加载本地 HTML 文件 index.html,
url: "file:///../../htmlfiles/index.html"
但它不起作用。
你能帮忙吗?
我正在尝试让 QML (main.qml) 加载本地 HTML 文件 index.html,
url: "file:///../../htmlfiles/index.html"
但它不起作用。
你能帮忙吗?
我最终使用并用于解决问题qApp->applicationDirPath()
从 c++ 传递到 QML 。setContextProperty()
url: "file:///" + applicationDirPath + "/htmlfiles/index.html"
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
}
}
这对我有用!
尝试不使用file:///
:
WebView {
url: "../../htmlfiles/index.html"
// [...]
}
有更简单的方法可以做到这一点:
WebView {
id: translationsList
anchors.fill: parent
url: "qrc:/about.html"
}
尝试:文件名=“/etc/issue”;url = Qt.resolvedUrl( 文件名 );