diff options
author | Bradley T. Hughes <bradley.hughes@nokia.com> | 2009-06-23 05:53:53 (GMT) |
---|---|---|
committer | Bradley T. Hughes <bradley.hughes@nokia.com> | 2009-06-23 05:53:53 (GMT) |
commit | fbe44b843194f3892e163ecec1be52fb498e2ddd (patch) | |
tree | 857c749710a71e2d485bd134d6542c62ac51c4e5 /doc/src/snippets/code | |
parent | 6fc3873707ae9e8c002b14800bac9fd64faca42b (diff) | |
parent | 3647de5291db9e359e7844f80202251f47e83a97 (diff) | |
download | Qt-fbe44b843194f3892e163ecec1be52fb498e2ddd.zip Qt-fbe44b843194f3892e163ecec1be52fb498e2ddd.tar.gz Qt-fbe44b843194f3892e163ecec1be52fb498e2ddd.tar.bz2 |
Merge branch 'master' of git@scm.dev.nokia.troll.no:qt/qt
Diffstat (limited to 'doc/src/snippets/code')
-rw-r--r-- | doc/src/snippets/code/src_network_access_qnetworkdiskcache.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/doc/src/snippets/code/src_network_access_qnetworkdiskcache.cpp b/doc/src/snippets/code/src_network_access_qnetworkdiskcache.cpp new file mode 100644 index 0000000..acd3938 --- /dev/null +++ b/doc/src/snippets/code/src_network_access_qnetworkdiskcache.cpp @@ -0,0 +1,24 @@ +//! [0] +QNetworkAccessManager *manager = new QNetworkAccessManager(this); +QNetworkDiskCache *diskCache = new QNetworkDiskCache(this); +diskCache->setCacheDirectory("cacheDir"); +manager->setCache(diskCache); +//! [0] + +//! [1] +// do a normal request (preferred from network, as this is the default) +QNetworkRequest request(QUrl(QString("http://www.qtsoftware.com"))); +manager->get(request); + +// do a request preferred from cache +QNetworkRequest request2(QUrl(QString("http://www.qtsoftware.com"))); +request2.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); +manager->get(request2); +//! [1] + +//! [2] +void replyFinished(QNetworkReply *reply) { + QVariant fromCache = reply->attribute(QNetworkRequest::SourceIsFromCacheAttribute); + qDebug() << "page from cache?" << fromCache.toBool(); +} +//! [2] |