Search code examples
qturlwebviewqmlrelative-path

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.

Can you please help?


Solution

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