Stan R
Stan R

Reputation: 41

Qt 5.6 webengine display local HTML file

I am trying to learn qt webengine, I downloaded qt 5.6 and looked at example on how to display simple web page. But now I want to learn how to display an HTML page that's store locally. I've seen few example like this one: How do I display local HTML in QWebview?

And it seems it's for older WebKit ? In the example for qt it shows main.qml file which point to qt.io website.

How can I point that to my local HTML file? I've placed qrc:/HTML/index.html and when I run my program it says can't find page.

I placed my HTML file in HTML folder which is located in same directory where main.qml file located.

I am very new to qt, and I would appreciate any help I can get. Thanks

Upvotes: 4

Views: 3764

Answers (1)

Kevin Krammer
Kevin Krammer

Reputation: 5207

If your HTML file is in the same folder as the QML file, the just use the file name of the HTML file as the "URL" to load.

Relative URLs in QML are relative to the current file.

If your QML file is built into the application using Qt's resource system, i.e. if you are specifying a qrc URL when loading the main QML in your C++ code, make sure the HTML file is also added to the resource system.

If the main QML file is loaded from the file system, nothing else is required.

Upvotes: 2

Related Questions