[Solved] QWebView using setHtml :- images do not refresh
-
I'm using setHTML to display some generated, template-based HTML which also contains some generated images. By template-based, I mean that I have a "template" HTML file which I read in as text, then I replace some portions of this text with data generated from my application, then set the result in the WebView using setHtml(). My application also includes a couple of images, which have fixed filenames, which the application generates, and which are displayed in the QWebView.
This all works fine the first time.
The problem I have is that if the application data changes, and I regenerate the HTML, and save new images (overwriting the previous ones) the QWebView (or some internal component) doesn't display the changed images - I presume it uses cached copies of the images which use the same names.
Normally, things work ok if you Refresh (QWebPage::Reload) - that is, if you're rendering a file or server-based page - then images are updated. However, in the this case of using setHtml(), the refresh actually reloads the HTML based on the URL given in the setHtml baseUrl parameter - in my case it opens my template HTML file (I need pass this in setHtml so that the correct paths are used to find the style sheet(s) and images).
Clearly I can fix this by using a temporary file - basically put my generated HTML in there, and just load that file normally, and all should work with a refresh. Actually this is not an issue since my files are small.
Still I feel it's not quite right, and I suppose that this could be a problem when using these classes for manual editting for example.
So, does this issue ring any bells with anyone ? Does something similar happen when editting pages ? Is there an image cache which can be forced to refresh which I've missed in the docs ? Or is there some less explicit way to get the cache to update, or to switch off ? (I tried settings->setMaximumPagesInCache( 0 );)
-
Hi Timothy,
try this:
myWebView->settings()->setObjectCacheCapacities(0,0,0);
Rgds
-
bq. myWebView->settings()->setObjectCacheCapacities(0,0,0);
Ah - yes ! Nice - thanks Steven !
(although reading the docs didn't shed much light on the matter ;-)