[SOLVED] Display HTML from QRC in WebEngineView



  • I would like to display HTML files (with associated JS and CSS) that get bundled with my application in QRC in a WebEngineView (I'd prefer to use QML, but if necessary I can use widgets). How can I do this? I've tried loading "qrc:/index.html" as the URL in both a QML and widgets based application, and in both cases the web engine assumes index.html is a domain and fails on the DNS lookup.

    Where am I going wrong here? Thanks. :)


  • Moderators

    Hi @Nathan-H,
    AFAIK it is still not supported as it just invokes the underlying platforms webview and it wont understand the Qt's Resource System. Instead you can read the HTML file from qrc on C++ side and pass it as a string to QML where you can use loadHtml to load it in web view.



  • I've looked at using loadHTML, but the page I'm loading pulls in external resources like image, JS and CSS files. How do I load those when those files are also in QRC?


  • Moderators

    @Nathan-H AFAIK it will work. Try using qrc:/ before source files.
    P.S: Good news is loading HTML file from qrc now works in Qt 5.5.



  • @p3c0 Is there any docs on that? I'm using 5.5, and it doesn't work...



  • Using a qrc:/ url definitely works. I routinely load css and js files into a WebEngineView with urls (inside the html) like "qrc:/blah.js" and setting the url of a WebEngineView to "qrc:/index.html" also works as expected. If it's not working for you, there's some other problem.



  • OK, so I just tried it again and now it works. No idea what's different from earlier this week, but I'm glad it works now. :]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.