[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:
ui->webView->load(QUrl::fromLocalFile("c://sample//index.html"));
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:
src="js/util.js"
Then still, everything works just fine.
However, if I instead want the JS files to be in some other path, like
c:\scripts\util.jsand include them within the HTML like this:
src="c:/scripts/util.js"
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.
Thanks
-
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:
src="file:///c:/scripts/util.js"
rather than:
src=“c:/scripts/util.js”