PDA

View Full Version : Saving webkit page image resources from memory



jerome
14th January 2012, 10:39
Hi all,

I have a quick question and would appreciate it someone could tell me if im completely off the track.

What I'm trying to do save to disc all loaded images in memory that come from a page that is loaded by webkit.
What I have done is intercept each QUrl by subclassing the QNetworkAccessManager which gives me the URL of the file its is referencing on override method "createRequest". This is fine however I am interested in the URL and image data when the request is finished (when createRequest is called the data parameter is empty although I do get the URL and other bit of information). I would like to intercept the loaded image data and save each to the harddrive. How would I intercept the loaded image data?

Am I heading in the right direction with this or there another better way to do this?

Thanks in advance

wysota
14th January 2012, 21:18
I think it might be easier to attach a custom network cache to WebKit's QNetworkAccessManager so that everything WebKit downloads goes to your custom code where you can do with it whatever you want.

jerome
14th January 2012, 22:39
thank you - you are a legend!

QNetworkAccessManager *manager = new QNetworkAccessManager(this);
QNetworkDiskCache *diskCache = new QNetworkDiskCache(this);
diskCache->setCacheDirectory("cacheDir");
manager->setCache(diskCache);

That gives me a local folder with the cached files. From there I added a finished signal to the QNetworkAccessManager and dug into the cached files : manager->cache()->data(QUrl)->readAll()
and hey presto!

I had one main problem with my previous attempt - I was not able to get a bytearray for images back from the QNetworkAccessManager finished callback for some reason? I could intercept text though. strange.

Thank you so much