【发布时间】:2011-05-24 19:49:48
【问题描述】:
我正在尝试让 QML (main.qml) 加载本地 HTML 文件 index.html 使用
url: "file:///../../htmlfiles/index.html"
但它不起作用。
你能帮忙吗?
【问题讨论】:
标签: qt url webview qml relative-path
我正在尝试让 QML (main.qml) 加载本地 HTML 文件 index.html 使用
url: "file:///../../htmlfiles/index.html"
但它不起作用。
你能帮忙吗?
【问题讨论】:
标签: qt url webview qml relative-path
我最终使用 setContextProperty() 将 qApp->applicationDirPath() 从 c++ 传递到 QML,并使用 url: "file:///" + applicationDirPath + "/htmlfiles/index.html" 解决了这个问题。
【讨论】:
engine.rootContext()->setContextProperty("workingDirectory", QUrl::fromLocalFile(app.applicationDirPath())); 在 Qt 5 中。
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( 文件名 );
【讨论】: