I want to render html from a QString in QWebView using
QWebView::setHtml( QString, QUrl );
The images should be loaded from a temporary directory c:/temp. In html code the images are referred only by file-names, without path e.g.
<img src="myimage.png">
I provide this path as the baseUrl with the 2nd parameter of setHtml, but the images are not rendered. I've tried to refer the images with full path:
<img src="c:/temp/myimage.png">
and it works correctly - the image is displayed.
I've checked, whether the url is valid:
QUrl base = QUrl::fromUserInput("c:/temp");
if (!base.isValid())
return false;
and the URL is reported as valid. What am I doing wrong here?
I'm working on Windows, with Qt 4.8.4
Thanks for any hints!
Solved! A right click on missing image symbol in QWebView reviled, that the image had not the address c:/temp/myimage.png as I expected but c:/myimage.png. I've tried to set the baseUrl as c:/temp/. and now everything works!
Looks like QWebView interpreted baseUrl as a html-file, relative to which the images are located. In my point of view it doesn't make sense for QWebView::setHtml
where the source comes from a string, and there is actually no html-file, only base-directory.