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


C++ QNetworkRequest::attribute方法代码示例

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


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

示例1: finished

void ZAPI::finished()
{
    QNetworkReply* reply = (QNetworkReply*)sender();
    QNetworkRequest request = reply->request();
    int role = request.attribute(ATTR_ROLE).toInt();
    QString strReply = reply->readAll();
    QJsonDocument jsonDoc = QJsonDocument::fromJson(strReply.toUtf8());
    QJsonObject jsonObject = jsonDoc.object();
    //qDebug() << jsonDoc.toJson();
    switch(role) {
    case ROLE_LOGIN:
        access_token = jsonObject["access_token"].toString();
        token_type = jsonObject["token_type"].toString();
        emit loginSignal(jsonObject);
        break;
    case ROLE_REFRESH:
        break;
    case ROLE_URL:
        emit urlSignal(jsonObject);
        break;
    case ROLE_FEEDS:
        emit feedsSignal(jsonObject);
        break;
    }
    reply->deleteLater();
}
开发者ID:heaven0sky,项目名称:zhihupc,代码行数:26,代码来源:zapi.cpp

示例2: onDeletePasteFinished

void Pastebin::onDeletePasteFinished()
{
    QNetworkReply *networkReply = qobject_cast<QNetworkReply *>(sender());
    QNetworkRequest networkRequest = networkReply->request();
    QVariant statusCode = networkReply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    const QString pasteKey = networkRequest.attribute(QNetworkRequest::Attribute(QNetworkRequest::User + 1)).toString();
    qDebug() << "Delete paste complete:" << statusCode.toInt();

    if(networkReply->error() == QNetworkReply::NoError) {
        QString response = networkReply->readAll();

        qDebug() << "Response:" << response;

        if(response.startsWith("Bad API request")) {
            qWarning() << "Error with delete paste";
            emit deletePasteError(pasteKey, response);
        }
        else {
            qDebug() << "Delete paste successful";
            emit deletePasteComplete(pasteKey);
        }
    }
    else {
        qWarning() << "Error with delete paste" << networkReply->errorString();
        emit deletePasteError(pasteKey, QString::null);
    }
}
开发者ID:dkonigsberg,项目名称:LogicPaste,代码行数:27,代码来源:Pastebin.cpp

示例3: downloadRequested

void DownloadManager::downloadRequested(const QNetworkRequest& request) {
    std::cout << "DownloadManager::DownloadRequested()\n";
    QString src = request.url().toString();
    QString dest = request.attribute(QNetworkRequest::User, "~").toString();

    QFile* fileDestination = new QFile(dest);
    fileDestination->open(QIODevice::ReadWrite);
    QNetworkReply* reply = mNetworkAccess.get(request);
    reply->setReadBufferSize(0);
    mActiveDownloads.insert(reply, fileDestination);

    connect(reply, SIGNAL(finished()), this, SLOT(downloadFinished()));
    connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError)));
    connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64)));
    connect(reply, SIGNAL(readyRead()), this, SLOT(downloadReadyRead()));

    DownloadData* data = new DownloadData();
    data->mRemotePath = src;
    data->mLocalPath = dest;

    connect(reply, SIGNAL(finished()), data, SLOT(finished()));

    connect(reply, SIGNAL(downloadProgress(qint64, qint64)), data, SLOT(catchProgress(qint64, qint64)));
    connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), data, SIGNAL(error(QNetworkReply::NetworkError)));
    connect(data, SIGNAL(stopMe()), this, SLOT(stopDownload()));
    connect(data, SIGNAL(removeMe()), this, SLOT(removeDownload()));
    //connect(data, SIGNAL(reloadMe()), this, SLOT(reloadDownload()));

    emit downloadStarted(data);
    emit controller_showSystemTrayMessage("", "Download Started: " + data->localName());
    mModel.addDownload(data);
    mDownloads.insert(data, reply);
}
开发者ID:jeremykross,项目名称:Trek-Browser,代码行数:33,代码来源:DownloadManager.cpp

示例4: capabilitiesReplyFinished

void QgsWcsCapabilities::capabilitiesReplyFinished()
{
  if ( mCapabilitiesReply->error() == QNetworkReply::NoError )
  {
    QVariant redirect = mCapabilitiesReply->attribute( QNetworkRequest::RedirectionTargetAttribute );
    if ( !redirect.isNull() )
    {
      emit statusChanged( tr( "Capabilities request redirected." ) );

      QNetworkRequest request( redirect.toUrl() );
      setAuthorization( request );
      request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork );
      request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );

      mCapabilitiesReply->deleteLater();
      QgsDebugMsg( QString( "redirected getcapabilities: %1" ).arg( redirect.toString() ) );
      mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );

      connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) );
      connect( mCapabilitiesReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( capabilitiesReplyProgress( qint64, qint64 ) ) );
      return;
    }

    mCapabilitiesResponse = mCapabilitiesReply->readAll();

    if ( mCapabilitiesResponse.isEmpty() )
    {
      mErrorFormat = "text/plain";
      mError = tr( "empty of capabilities: %1" ).arg( mCapabilitiesReply->errorString() );
    }
  }
  else
  {
    // Resend request if AlwaysCache
    QNetworkRequest request = mCapabilitiesReply->request();
    if ( request.attribute( QNetworkRequest::CacheLoadControlAttribute ).toInt() == QNetworkRequest::AlwaysCache )
    {
      QgsDebugMsg( "Resend request with PreferCache" );
      request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache );

      mCapabilitiesReply->deleteLater();

      mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );
      connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) );
      connect( mCapabilitiesReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( capabilitiesReplyProgress( qint64, qint64 ) ) );
      return;
    }

    mErrorFormat = "text/plain";
    mError = tr( "Download of capabilities failed: %1" ).arg( mCapabilitiesReply->errorString() );
    QgsMessageLog::logMessage( mError, tr( "WCS" ) );
    mCapabilitiesResponse.clear();
  }

  mCapabilitiesReply->deleteLater();
  mCapabilitiesReply = 0;
}
开发者ID:AnAvidDeveloper,项目名称:QGIS,代码行数:57,代码来源:qgswcscapabilities.cpp

示例5: Source

static inline QString Source(const QNetworkRequest &request)
{
    switch (request.attribute(QNetworkRequest::CacheLoadControlAttribute).toInt())
    {
    case QNetworkRequest::AlwaysCache: return "cache";
    case QNetworkRequest::PreferCache: return "cache-preferred";
    case QNetworkRequest::PreferNetwork: return "net-preferred";
    case QNetworkRequest::AlwaysNetwork: return "net";
    }
    return "unknown";
}
开发者ID:aravilife,项目名称:mythtv-stabilize2,代码行数:11,代码来源:netstream.cpp

示例6: QObject

GM_Downloader::GM_Downloader(const QNetworkRequest &request, GM_Manager* manager)
    : QObject()
    , m_manager(manager)
    , m_widget(0)
{
    m_reply = new FollowRedirectReply(request.url(), mApp->networkManager());
    connect(m_reply, SIGNAL(finished()), this, SLOT(scriptDownloaded()));

    QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
    WebPage* webPage = static_cast<WebPage*>(v.value<void*>());

    if (WebPage::isPointerSafeToUse(webPage)) {
        m_widget = webPage->view();
    }
}
开发者ID:593in,项目名称:qupzilla,代码行数:15,代码来源:gm_downloader.cpp

示例7: createRequest

QNetworkReply* NetworkManager::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice* outgoingData)
{
    if (op == PostOperation && outgoingData) {
        QByteArray outgoingDataByteArray = outgoingData->peek(1024 * 1024);
        mApp->autoFill()->post(request, outgoingDataByteArray);
    }

    QNetworkRequest req = request;
    QNetworkReply* reply = 0;

    if (m_doNotTrack) {
        req.setRawHeader("DNT", "1");
    }

    if (!m_sendReferer) {
        req.setRawHeader("Referer", "");
    }

    req.setRawHeader("Accept-Language", m_acceptLanguage);

    //SchemeHandlers
    if (req.url().scheme() == "qupzilla") {
        reply = m_qupzillaSchemeHandler->createRequest(op, req, outgoingData);
        if (reply) {
            return reply;
        }
    }

    req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
    if (req.attribute(QNetworkRequest::CacheLoadControlAttribute).toInt() == QNetworkRequest::PreferNetwork) {
        req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
    }

    // Adblock
    if (op == QNetworkAccessManager::GetOperation) {
        if (!m_adblockNetwork) {
            m_adblockNetwork = AdBlockManager::instance()->network();
        }
        reply = m_adblockNetwork->block(req);
        if (reply) {
            return reply;
        }
    }

    reply = QNetworkAccessManager::createRequest(op, req, outgoingData);
    return reply;
}
开发者ID:Shadowmeph,项目名称:QupZilla,代码行数:47,代码来源:networkmanager.cpp

示例8: setSSLConfiguration

void NetworkManager::setSSLConfiguration(QNetworkReply* reply)
{
    if (!reply->sslConfiguration().isNull()) {
        QSslCertificate cert = reply->sslConfiguration().peerCertificate();
        if (!cert.isValid() || reply->property("downReply").toBool()) {
            return;
        }

        QNetworkRequest request = reply->request();
        QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
        WebPage* webPage = static_cast<WebPage*>(v.value<void*>());
        if (!webPage) {
            return;
        }

        if (webPage->url().host() == reply->url().host()) {
            webPage->setSSLCertificate(cert);
        }
    }
}
开发者ID:Shadowmeph,项目名称:QupZilla,代码行数:20,代码来源:networkmanager.cpp

示例9: onRequestRawPasteFinished

void Pastebin::onRequestRawPasteFinished() {
    QNetworkReply *networkReply = qobject_cast<QNetworkReply *>(sender());
    QNetworkRequest networkRequest = networkReply->request();
    QVariant statusCode = networkReply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    const QString pasteKey = networkRequest.attribute(QNetworkRequest::Attribute(QNetworkRequest::User + 1)).toString();
    qDebug() << "Paste request complete:" << statusCode.toInt();
    networkReply->deleteLater();

    if(networkReply->error() == QNetworkReply::NoError) {
        const QByteArray data = networkReply->readAll();

        if(!data.isEmpty()) {
            emit rawPasteAvailable(pasteKey, data);
        } else {
            emit rawPasteError(pasteKey);
        }
    } else {
        qWarning() << "Error requesting raw paste:" << networkReply->errorString();
        emit rawPasteError(pasteKey);
    }
}
开发者ID:dkonigsberg,项目名称:LogicPaste,代码行数:21,代码来源:Pastebin.cpp

示例10: requestFinished

void Ssu::requestFinished(QNetworkReply *reply){
  QSslConfiguration sslConfiguration = reply->sslConfiguration();
  SsuLog *ssuLog = SsuLog::instance();
  SsuCoreConfig *settings = SsuCoreConfig::instance();
  QNetworkRequest request = reply->request();
  QVariant originalDomainVariant = request.attribute(SSU_NETWORK_REQUEST_DOMAIN_DATA);

#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
  ssuLog->print(LOG_DEBUG, QString("Certificate used was issued for '%1' by '%2'. Complete chain:")
                .arg(sslConfiguration.peerCertificate().subjectInfo(QSslCertificate::CommonName).join(""))
                .arg(sslConfiguration.peerCertificate().issuerInfo(QSslCertificate::CommonName).join("")));

  foreach (const QSslCertificate cert, sslConfiguration.peerCertificateChain()){
    ssuLog->print(LOG_DEBUG, QString("-> %1").arg(cert.subjectInfo(QSslCertificate::CommonName).join("")));
  }
#else
  ssuLog->print(LOG_DEBUG, QString("Certificate used was issued for '%1' by '%2'. Complete chain:")
               .arg(sslConfiguration.peerCertificate().subjectInfo(QSslCertificate::CommonName))
               .arg(sslConfiguration.peerCertificate().issuerInfo(QSslCertificate::CommonName)));

  foreach (const QSslCertificate cert, sslConfiguration.peerCertificateChain()){
    ssuLog->print(LOG_DEBUG, QString("-> %1").arg(cert.subjectInfo(QSslCertificate::CommonName)));
  }
#endif

  pendingRequests--;

  QString action;
  QByteArray data;
  QDomDocument doc;
  QString xmlError;

  /// @TODO: indicate that the device is not registered if there's a 404 on credentials update url
  if (settings->contains("home-url")){
    QString homeUrl = settings->value("home-url").toString().arg("");
    homeUrl.remove(QRegExp("//+$"));

    if (request.url().toString().startsWith(homeUrl, Qt::CaseInsensitive)){
      // we don't care about errors on download request
      if (reply->error() == 0) {
          QByteArray data = reply->readAll();
          storeAuthorizedKeys(data);
      }

      goto success;
    }
  }

  if (reply->error() > 0){
    setError(reply->errorString());
    goto failure;
  }

  data = reply->readAll();
  ssuLog->print(LOG_DEBUG, QString("RequestOutput %1")
                .arg(data.data()));

  if (!doc.setContent(data, &xmlError)){
    setError(tr("Unable to parse server response (%1)").arg(xmlError));
    goto failure;
  }

  action = doc.elementsByTagName("action").at(0).toElement().text();

  if (!verifyResponse(&doc)) {
    goto failure;
  }

  ssuLog->print(LOG_DEBUG, QString("Handling request of type %1")
                .arg(action));
  if (action == "register") {
    if (registerDevice(&doc)) {
      goto success;
    }
  } else if (action == "credentials") {
    if (setCredentials(&doc)) {
      goto success;
    }
  } else {
    setError(tr("Response to unknown action encountered: %1").arg(action));
  }

failure:
  // Restore the original domain in case of failures with the registration
  if (!originalDomainVariant.isNull()) {
    QString originalDomain = originalDomainVariant.toString();
    ssuLog->print(LOG_DEBUG, QString("Restoring domain on error: '%1'").arg(originalDomain));
    setDomain(originalDomain);
  }

  // Fall through to cleanup handling in success from failure label
success:
  ssuLog->print(LOG_DEBUG, QString("Request finished, pending requests: %1").arg(pendingRequests));
  if (pendingRequests == 0) {
    emit done();
  }
}
开发者ID:jvihrial,项目名称:ssu,代码行数:97,代码来源:ssu.cpp

示例11: replyFinished

void Petrel::replyFinished(QNetworkReply *reply)
{
    QNetworkRequest request = reply->request();
    QString replyStr( reply->readAll() );
    int role = request.attribute( (QNetworkRequest::Attribute)(QNetworkRequest::User + ATTR_ROLE) ).toInt();
    QDomDocument doc;
    doc.setContent(replyStr);
    switch(role){
        //autogenerated choice
        case AVAILABLE_TRENDS:
        {
          locations_t l(doc.documentElement());
          emit availableTrendsReceived(l);
          break;
        }
        case BLOCKING_IDS_BLOCKS:
        {
          ids_t i(doc.documentElement());
          emit blocking_IdsBlocksReceived(i);
          break;
        }
        case CREATE_BLOCK:
        {
          user_t u(doc.documentElement());
          emit createBlockReceived(u);
          break;
        }
        case CREATE_FAVORITE:
        {
          status_t s(doc.documentElement());
          emit createFavoriteReceived(s);
          break;
        }
        case CREATE_FRIENDSHIP:
        {
          user_t u(doc.documentElement());
          emit createFriendshipReceived(u);
          break;
        }
        case CREATE_SAVED_SEARCH:
        {
          saved_search_t s(doc.documentElement());
          emit createSavedSearchReceived(s);
          break;
        }
        case DELETE_LIST_ID:
        {
          list_t l(doc.documentElement());
          emit deleteListIdReceived(l);
          break;
        }
        case DELETE_LIST_MEMBER:
        {
          list_t l(doc.documentElement());
          emit deleteListMemberReceived(l);
          break;
        }
        case DELETE_LIST_SUBSCRIBER:
        {
          list_t l(doc.documentElement());
          emit deleteListSubscriberReceived(l);
          break;
        }
        case DESTROY:
        {
          status_t s(doc.documentElement());
          emit destroyReceived(s);
          break;
        }
        case DESTROY_BLOCK:
        {
          user_t u(doc.documentElement());
          emit destroyBlockReceived(u);
          break;
        }
        case DESTROY_DIRECT_MESSAGE:
        {
          direct_message_t d(doc.documentElement());
          emit destroyDirectMessageReceived(d);
          break;
        }
        case DESTROY_FAVORITE:
        {
          status_t s(doc.documentElement());
          emit destroyFavoriteReceived(s);
          break;
        }
        case DESTROY_FRIENDSHIP:
        {
          user_t u(doc.documentElement());
          emit destroyFriendshipReceived(u);
          break;
        }
        case DESTROY_SAVED_SEARCH:
        {
          saved_search_t s(doc.documentElement());
          emit destroySavedSearchReceived(s);
          break;
        }
        case DIRECT_MESSAGES:
//.........这里部分代码省略.........
开发者ID:plus7,项目名称:TwApiScraper,代码行数:101,代码来源:petrel.cpp

示例12: setup

void QNetworkReplyImplPrivate::setup(QNetworkAccessManager::Operation op, const QNetworkRequest &req,
                                     QIODevice *data)
{
    Q_Q(QNetworkReplyImpl);

    outgoingData = data;
    request = req;
    url = request.url();
    operation = op;

    q->QIODevice::open(QIODevice::ReadOnly);
    // Internal code that does a HTTP reply for the synchronous Ajax
    // in QtWebKit.
    QVariant synchronousHttpAttribute = req.attribute(
            static_cast<QNetworkRequest::Attribute>(QNetworkRequest::SynchronousRequestAttribute));
    // The synchronous HTTP is a corner case, we will put all upload data in one big QByteArray in the outgoingDataBuffer.
    // Yes, this is not the most efficient thing to do, but on the other hand synchronous XHR needs to die anyway.
    if (synchronousHttpAttribute.toBool() && outgoingData) {
        outgoingDataBuffer = QSharedPointer<QRingBuffer>(new QRingBuffer());
        qint64 previousDataSize = 0;
        do {
            previousDataSize = outgoingDataBuffer->size();
            outgoingDataBuffer->append(outgoingData->readAll());
        } while (outgoingDataBuffer->size() != previousDataSize);
    }

    if (backend)
        backend->setSynchronous(synchronousHttpAttribute.toBool());


    if (outgoingData && backend && !backend->isSynchronous()) {
        // there is data to be uploaded, e.g. HTTP POST.

        if (!backend->needsResetableUploadData() || !outgoingData->isSequential()) {
            // backend does not need upload buffering or
            // fixed size non-sequential
            // just start the operation
            QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection);
        } else {
            bool bufferingDisallowed =
                    req.attribute(QNetworkRequest::DoNotBufferUploadDataAttribute,
                                  false).toBool();

            if (bufferingDisallowed) {
                // if a valid content-length header for the request was supplied, we can disable buffering
                // if not, we will buffer anyway
                if (req.header(QNetworkRequest::ContentLengthHeader).isValid()) {
                    QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection);
                } else {
                    state = Buffering;
                    QMetaObject::invokeMethod(q, "_q_bufferOutgoingData", Qt::QueuedConnection);
                }
            } else {
                // _q_startOperation will be called when the buffering has finished.
                state = Buffering;
                QMetaObject::invokeMethod(q, "_q_bufferOutgoingData", Qt::QueuedConnection);
            }
        }
    } else {
        // for HTTP, we want to send out the request as fast as possible to the network, without
        // invoking methods in a QueuedConnection
#ifndef QT_NO_HTTP
        if (backend && backend->isSynchronous()) {
            _q_startOperation();
        } else {
            QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection);
        }
#else
        if (backend && backend->isSynchronous())
            _q_startOperation();
        else
            QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection);
#endif // QT_NO_HTTP
        }
}
开发者ID:KDE,项目名称:android-qt5-qtbase,代码行数:75,代码来源:qnetworkreplyimpl.cpp

示例13: downloadRequest

void KWebPage::downloadRequest(const QNetworkRequest &request)
{
    downloadResource(request.url(), QString(), view(),
                     request.attribute(static_cast<QNetworkRequest::Attribute>(KIO::AccessManager::MetaData)).toMap());
}
开发者ID:vasi,项目名称:kdelibs,代码行数:5,代码来源:kwebpage.cpp

示例14: post

void AutoFillModel::post(const QNetworkRequest &request, const QByteArray &outgoingData)
{
    //Dont save in private browsing
    if (mApp->webSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled)) {
        return;
    }

    m_lastOutgoingData = outgoingData;

    QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
    WebPage* webPage = static_cast<WebPage*>(v.value<void*>());
    if (!webPage) {
        return;
    }
    WebView* webView = qobject_cast<WebView*>(webPage->view());
    if (!webView) {
        return;
    }

    v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 101));
    QWebPage::NavigationType type = (QWebPage::NavigationType)v.toInt();

    if (type != QWebPage::NavigationTypeFormSubmitted) {
        return;
    }

    QString usernameName;
    QString usernameValue;
    QString passwordName;
    QString passwordValue;
    QUrl siteUrl = webPage->url();

    if (!isStoringEnabled(siteUrl)) {
        return;
    }

    QWebElementCollection allForms; // All form elements on page
    QWebElement foundForm;          // Sent form element

    QList<QWebFrame*> frames;
    frames.append(webPage->mainFrame());  // Find all form elements
    while (!frames.isEmpty()) {
        QWebFrame* frame = frames.takeFirst();
        allForms.append(frame->findAllElements("form"));
        frames += frame->childFrames();
    }

    foreach(const QWebElement & formElement, allForms) {
        foreach(const QWebElement &inputElement, formElement.findAll("input[type=\"password\"]")) {
            passwordName = inputElement.attribute("name");
            passwordValue = getValueFromData(outgoingData, inputElement);

            if (!passwordValue.isEmpty() && dataContains(outgoingData, passwordName)) {
                foundForm = formElement;
                break;
            }
        }

        if (!foundForm.isNull()) {
            break;
        }
    }
开发者ID:Shadowmeph,项目名称:QupZilla,代码行数:62,代码来源:autofillmodel.cpp

示例15: handleRelease

void Discogs::handleRelease( QNetworkReply* reply ){

    Album album;
    QNetworkRequest request = reply->request();
    QString key = request.attribute(QNetworkRequest::User).toString();

    if( albums_.contains(key) ){
        album = albums_[key];
        //album.setArtists( QStringList() );
        //album.setSongs( QList<Song>() );
    }


    //cover->setText("");
    QString err;
    QByteArray response(reply->readAll());
    QXmlStreamReader xml(response);

    QList<Artist> Artists;
    QList<QUrl> images;
    QStringList artists,roles;
    QList<Song> songs;
    while (!xml.atEnd()) {
        xml.readNext();
        //qDebug()<<xml.name();

        if( xml.name() == "release" && xml.attributes().hasAttribute("id") ){
            QString id = xml.attributes().value("id").toString();
            album.setRelease(id);
        }

        if(xml.tokenType() == QXmlStreamReader::StartElement){
            if( xml.attributes().hasAttribute("stat") ){
                QString stat = xml.attributes().value("stat").toString();
                if(stat=="fail"){
                    while(xml.readNextStartElement()){
                        if( xml.name() == "error" ){
                            err.append(xml.readElementText()+"\n");
                        }else{
                            xml.skipCurrentElement();
                        }
                    }
                }
            }
            if( xml.attributes().hasAttribute("requests") ){
                //&nSearches = xml.attributes().value("requests").toString().toInt();
                //info->setText(QString::number(nSearches)+" searches performed within the last 24 hours");
            }
            if(xml.name() == "images"){
                xml.readNext();
                while(xml.name()=="image"){
                    if( xml.attributes().hasAttribute("uri") ){
                        images.append( QUrl( xml.attributes().value("uri").toString() ) );
                        //qDebug()<<"found image "<<xml.attributes().value("uri").toString();
                    }
                    xml.readNext();
                }
            }
            if(xml.name() == "artists"){
                while(xml.readNextStartElement()){
                    if(xml.name() == "artist"){
                        while(xml.readNextStartElement()){
                            if(xml.name() == "name"){
                                artists.append( xml.readElementText() );
                            }else{
                                xml.skipCurrentElement();
                            }
                        }
                    }else{
                        xml.skipCurrentElement();
                    }
                }
            }
            if(xml.name() == "extraartists"){
                while(xml.readNextStartElement()){
                    if(xml.name() == "artist"){
                        //QString name;QString role;
                        Artist a;
                        while(xml.readNextStartElement()){
                            if(xml.name() == "name"){
                                a.setName( xml.readElementText() );
                            }else if(xml.name() == "role"){
                                a.setRole( xml.readElementText() );
                            }else{
                                xml.skipCurrentElement();
                            }
                            Artists.append(a);
                        }
                        //qDebug()<<role+": "+name;
                        //album.roles.append( role+": "+name );
                    }else{
                        xml.skipCurrentElement();
                    }
                }
            }
            if(xml.name() == "formats"){
                while(xml.readNextStartElement()){
                    if( xml.name()=="format" && xml.attributes().hasAttribute("name") ){
                        QString sep=", ";
                        if(album.format().isEmpty()){
//.........这里部分代码省略.........
开发者ID:ivareske,项目名称:TagEditor,代码行数:101,代码来源:Discogs.cpp


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