Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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);
    diskCache->setCacheDirectory("cacheDir");
    manager->setCache(diskCache);
    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?
    @
    diskCache->setCacheDirectory("cacheDir");
    @
    is this line create directory on project path??
    thanks in advance for your help :)


  • Moderators

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


Log in to reply