diff --git a/src/network/doc/snippets/code/src_network_access_qnetworkdiskcache.cpp b/src/network/doc/snippets/code/src_network_access_qnetworkdiskcache.cpp index f830439124..1087f52035 100644 --- a/src/network/doc/snippets/code/src_network_access_qnetworkdiskcache.cpp +++ b/src/network/doc/snippets/code/src_network_access_qnetworkdiskcache.cpp @@ -4,17 +4,20 @@ //! [0] QNetworkAccessManager *manager = new QNetworkAccessManager(this); QNetworkDiskCache *diskCache = new QNetworkDiskCache(this); -diskCache->setCacheDirectory("cacheDir"); +QString directory = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + + QLatin1StringView("/cacheDir/"); +diskCache->setCacheDirectory(directory); manager->setCache(diskCache); //! [0] //! [1] +using namespace Qt::StringLiterals; // do a normal request (preferred from network, as this is the default) -QNetworkRequest request(QUrl(QString("http://qt-project.org"))); +QNetworkRequest request(QUrl(u"http://qt-project.org"_s)); manager->get(request); // do a request preferred from cache -QNetworkRequest request2(QUrl(QString("http://qt-project.org"))); +QNetworkRequest request2(QUrl(u"http://qt-project.org"_s)); request2.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); manager->get(request2); //! [1]