PDA

View Full Version : Using cache with QNetworkAccessManager in QWebEngine



d1psy
18th August 2016, 09:14
So. I've found this post http://www.qtcentre.org/threads/46263-Using-cache-with-QNetworkAccessManager
And looks like it doesn't work this way in QWebEngine. When I'm trying to load my programm in QWebKit, it shows cached page. But when I'm using QWebEngine, it shows regular chromium's "No internet connection" page. How should I change code in order for it to work in QWebEngine?
Thanks for your help!

anda_skoa
18th August 2016, 09:49
QWebEngine doesn't use QNetworkAccessManager, the network handling is part of the web process which is the provided by the Chromium engine code.

It looks like the QWebEngineProfile has cache settings though.
Accessible through the view's QWebEnginePage.

Cheers,
_

d1psy
18th August 2016, 11:26
Still can't understand how to remake it, so now it would cache and load cached page...

Added after 6 minutes:

All I need to know is - how to save and load cache in QWebEngine?

anda_skoa
18th August 2016, 12:09
So if you set a file based cache type (which should be the default according to documentation), does QWebEngine not save anything?
Maybe try setting the cache path and see if that directory gets any files?

Maybe you need to set the http cache size.

Cheers,
_

d1psy
18th August 2016, 12:17
The path is set. Size is also set. But it just shows "No internet connection". But in QWebKit it works the way it's supposed to. It would be much easier if there was some kind of caching example in QWebEngine

Added after 4 minutes:

I've just created a simple "Hello!" html page and tried to open it offline through my program. It still showed me "No internet connection", instead of showing simple "Hello!"

anda_skoa
18th August 2016, 13:20
So the cache is only used when it could get the content from the actual server.

Maybe you need to set a request interceptor that, when no connection is available, redirects to the local file.

Cheers,
_