[Qt-interest] How to prevent QtWebKit from loading files with given extension?

Daniel Vérité daniel.verite at gmail.com
Thu Aug 20 02:25:06 CEST 2009


	 Piotr Dobrogost writes

> I'd like to prevent QtWebKit from loading files with given extension 
> (like .css in my case). How should I go about doing this? It would be 
> very nice and handy to be able to set filter of accepted file types in 
> QWebSettings.

You can do it by providing your own QNetworkManager-derived class, with
QWebPage::setNetworkAccessManager()
This class has a createRequest() function that is called by QtWebKit to load
each external object and that you want to reimplent.

In your implementation, to allow the request (based on its url), just return
QNetworkManager::createRequest() with the original arguments.

To deny the request, I instantiate a copy the QNetworkRequest object, set its
url to QUrl() and return the result of QNetworkManager::createRequest() for
that request. Not sure if it's the best method but it appears to work.

I'm using this to avoid hitting spammers pictures and webbugs when displaying
HTML mails.

Best regards,
-- 
 Daniel Vérité
 PostgreSQL-powered mail user agent and storage: http://www.manitou-mail.org 




More information about the Qt-interest-old mailing list