当前位置: 首页>>代码示例>>C++>>正文


C++ QNetworkCacheMetaData::setUrl方法代码示例

本文整理汇总了C++中QNetworkCacheMetaData::setUrl方法的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkCacheMetaData::setUrl方法的具体用法?C++ QNetworkCacheMetaData::setUrl怎么用?C++ QNetworkCacheMetaData::setUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QNetworkCacheMetaData的用法示例。


在下文中一共展示了QNetworkCacheMetaData::setUrl方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: initCacheSaveDevice

void QNetworkReplyImplPrivate::initCacheSaveDevice()
{
    Q_Q(QNetworkReplyImpl);

    // The disk cache does not support partial content, so don't even try to
    // save any such content into the cache.
    if (q->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 206) {
        cacheEnabled = false;
        return;
    }

    // save the meta data
    QNetworkCacheMetaData metaData;
    metaData.setUrl(url);
    metaData = backend->fetchCacheMetaData(metaData);

    // save the redirect request also in the cache
    QVariant redirectionTarget = q->attribute(QNetworkRequest::RedirectionTargetAttribute);
    if (redirectionTarget.isValid()) {
        QNetworkCacheMetaData::AttributesMap attributes = metaData.attributes();
        attributes.insert(QNetworkRequest::RedirectionTargetAttribute, redirectionTarget);
        metaData.setAttributes(attributes);
    }

    cacheSaveDevice = networkCache()->prepare(metaData);

    if (!cacheSaveDevice || (cacheSaveDevice && !cacheSaveDevice->isOpen())) {
        if (cacheSaveDevice && !cacheSaveDevice->isOpen())
            qCritical("QNetworkReplyImpl: network cache returned a device that is not open -- "
                  "class %s probably needs to be fixed",
                  networkCache()->metaObject()->className());

        networkCache()->remove(url);
        cacheSaveDevice = 0;
        cacheEnabled = false;
    } else {
        q->connect(networkCache(), SIGNAL(destroyed()), SLOT(_q_cacheDestroyed()));
    }
}
开发者ID:Suneal,项目名称:qt,代码行数:39,代码来源:qnetworkreplyimpl.cpp

示例2: saveToCache

bool saveToCache(const QUrl& url, const QByteArray& file) {
    if (auto cache = NetworkAccessManager::getInstance().cache()) {
        if (!cache->metaData(url).isValid()) {
            QNetworkCacheMetaData metaData;
            metaData.setUrl(url);
            metaData.setSaveToDisk(true);
            metaData.setLastModified(QDateTime::currentDateTime());
            metaData.setExpirationDate(QDateTime()); // Never expires

            // ioDevice is managed by the cache and should either be passed back to insert or remove!
            if (auto ioDevice = cache->prepare(metaData)) {
                ioDevice->write(file);
                cache->insert(ioDevice);
                qCDebug(asset_client) << url.toDisplayString() << "saved to disk cache";
                return true;
            }
            qCWarning(asset_client) << "Could not save" << url.toDisplayString() << "to disk cache.";
        }
    } else {
        qCWarning(asset_client) << "No disk cache to save assets to.";
    }
    return false;
}
开发者ID:howard-stearns,项目名称:hifi,代码行数:23,代码来源:AssetUtils.cpp


注:本文中的QNetworkCacheMetaData::setUrl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。