View Full Version : QNetworkAccessManager: disable cache for concrete document

15th December 2009, 18:50
I don't want to cache concrete image on website page (using many qwebview for one site). For this I overload QNetworkAccessManager's method createRequest(), make condition for my image (if (myReq.url() == myUrl) then not apply
cache), and try in this condition:
1) myReq.setRawHeader( new QByteArray("Cache-Control"), new QByteArray("no-cache") ); //not work
2) myReq.setRawHeader( new QByteArray("If-Modified-Since""), new QByteArray(myTime) ); //not work
3) myReq.setUrl(new QUrl(url2 + "&x=" + rand.nextInt(1000000))); //not work too, url becomes really other, but however image in cache.

How I must abolish cash for document (in my case - image)? Thanks.
p.s. sorry for my english

18th December 2009, 12:20
Probably I explained badly.
There is a lot of threads, each of them using QWebView. Also we have one url for each of them.
Task: to compel createRequest (method of QNetworkAccessManager) to take a resource (in my case it is gif-image on website) from the network, instead of from cache.

Some code of one thread:

this.webPage.page().setNetworkAccessManager(new CorrectNetworkAccessManager(this.ip, this.port));

Code of class CorrectNetworkAccessManager (which extends QNetworkAccessManager):

class CorrectNetworkAccessManager extends QNetworkAccessManager
int _port;
String _ip, userAgent, acceptLanguage, acceptCharset;

public CorrectNetworkAccessManager(String ip, int port)
this._ip = ip;
this._port = port;

protected QNetworkReply createRequest(Operation op, QNetworkRequest request, QIODevice outgoingData)
QNetworkRequest myReq = new QNetworkRequest(request);

/*This show url of each resource of webpage. If number of threads is 10 and webpage contains, for example, gif-image
(<img src="myimage.gif">), this method show us only ONE gif-image url, and it is necessary to do, that 10 showed. I.e.
to abolish cache for this picture. However, if webpage contains php-page, it show 10 times! (because php-page not
caching) */

this.userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.0 (KHTML, like Gecko)";
this.acceptLanguage = "ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4";
this.acceptCharset = "windows-1251,utf-8;q=0.7,*;q=0.3";

myReq.setRawHeader( new QByteArray("User-Agent"), new QByteArray(this.userAgent) );
myReq.setRawHeader( new QByteArray("Accept-Charset"), new QByteArray(this.acceptCharset) );
myReq.setRawHeader( new QByteArray("Accept-Language"), new QByteArray(this.acceptLanguage) );

How to abolish cach for image? Thanks for answers.