From a156b667ce7bee39cb5ea916c6872593de02a284 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Fri, 10 Mar 2023 18:22:54 +0100 Subject: [PATCH] QNetworkDiskCache: Update doc snippets We should encourage users to use the system cache directory. We should also encourage users to not use the char* QString-ctors. QStandardPaths::CacheLocation is documented to never be empty, so use it in this manner. Pick-to: 6.5 Change-Id: I1f050feda5b0a8e7c23fbed5db904bb0180b45f0 Reviewed-by: Timur Pocheptsov --- .../code/src_network_access_qnetworkdiskcache.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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]