Important: Please read the Qt Code of Conduct -

[SOLVED] problems loading local content into QWebView

  • I'm using Qt 5.2.1 on PC

    I have a simple QWebView and I load it with an HTML page that is stored on the local machine:


    This much works.

    This index.html will include several other javascript files and style-sheets.

    If I place those JS and CSS files all in a sub-folder "c:/sample/js" (for example) next to index.html and include them within my HTML like this:


    Then still, everything works just fine.

    However, if I instead want the JS files to be in some other path, like

    and include them within the HTML like this:


    Then the QWebView fails to load properly.. It still finds index.html and I can see some of the raw content, but it clearly failed to load any of the JS and CSS.

    The interesting thing is that either version of my HTML file, when double-clicked in the file-system, will load and render properly in the browser, finding the included JS and CSS regardless which way I reference them or where they are.

    So why does QtWebView fail when the CSS and JS files are not under a folder next to my index.html?

    Edit: I'm thinking maybe it's a security thing. I've tried setting to true both QWebSettings::LocalContentCanAccessRemoteUrls, and QWebSettings::LocalContentCanAccessFileUrls without any luck.


  • so I figured out how to get it to work, and it had nothing to do with Qt. Rather, my index.html had to use:


    rather than:


Log in to reply