Nominate our 2022 Qt Champions!

Caching Data

  • hello :)
    i'm using QNetworkAccessManager to get web service data
    i want to cache the recieved data so that when there is no connection i got the data from cache
    QNetworkDiskCache *diskCache = new QNetworkDiskCache(this);
    QNetworkRequest req(url);
    req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysCache);

    it get what has been cashed before and don't look 2 the server
    so i change this attribute 2 be
    req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
    but when there is no connection it got no data
    what can i do???
    by the way how i specify the path it will save data on the mobile?
    is this line create directory on project path??
    thanks in advance for your help :)

  • I added @ formatting tags to your code. Please be sure and use them in the future.

Log in to reply