PDA

View Full Version : QWebPage -- How do I intercept image URLs before downloading?



TheNewGuy
1st December 2009, 00:33
I am new to QT and new to C++. I am building a gui application that makes use of QWebView for the interface. I want to be able to intercept resource (images, javascript, css) urls prior to trying to access those resources so that I can change the URL.

Why do I want to do this?

I am using qrc files to manage images and urls, etc. This way they are included in the .exe. This means that resources need to be accessed using a url like this "/resource/index.html"

To speed up development, I would rather access the non-compiled versions of the html and load the html from the filesystem. This works perfect, except one problem... Webkit does not know how to handle urls such as "/resource/index.html" It can handle "./resource/index.html" but then when I am not developing it will not load that as a qrc url.

Does anyone have any ideas on how to do what I want to do?

wysota
3rd December 2009, 10:15
Either take a look at the QWebPage::downloadRequested() signal or provide your own QNetworkAccessManager with reimplemented createRequest() method for WebKit. The latter is probably what you want, the former only lets you see the request but doesn't allow to modify it.