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


C++ QVariant::toUrl方法代码示例

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


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

示例1: postFinished

void HttpHandler::postFinished(QNetworkReply* reply){
    QVariant possibleRedirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);

    /* We'll deduct if the redirection is valid in the redirectUrl function */
    qDebug() << "Redirect: " <<  possibleRedirectUrl.toUrl().toString();

    qDebug() << "File sent";
    QByteArray response = reply->readAll();
        printf("response: %s\n", response.data() );
        printf("reply error %d\n", reply->error() );
    reply->deleteLater();
    ba.clear();

}
开发者ID:Jonsku,项目名称:PhotoTheater,代码行数:14,代码来源:HttpHandler.cpp

示例2: sendCacheContents

bool QNetworkAccessCacheBackend::sendCacheContents()
{
    setCachingEnabled(false);
    QAbstractNetworkCache *nc = networkCache();
    if (!nc)
        return false;

    QNetworkCacheMetaData item = nc->metaData(url());
    if (!item.isValid())
        return false;

    QNetworkCacheMetaData::AttributesMap attributes = item.attributes();
    setAttribute(QNetworkRequest::HttpStatusCodeAttribute, attributes.value(QNetworkRequest::HttpStatusCodeAttribute));
    setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, attributes.value(QNetworkRequest::HttpReasonPhraseAttribute));

    // set the raw headers
    QNetworkCacheMetaData::RawHeaderList rawHeaders = item.rawHeaders();
    QNetworkCacheMetaData::RawHeaderList::ConstIterator it = rawHeaders.constBegin(),
                                                       end = rawHeaders.constEnd();
    for ( ; it != end; ++it) {
        if (it->first.toLower() == "cache-control" &&
            it->second.toLower().contains("must-revalidate")) {
            return false;
        }
        setRawHeader(it->first, it->second);
    }

    // handle a possible redirect
    QVariant redirectionTarget = attributes.value(QNetworkRequest::RedirectionTargetAttribute);
    if (redirectionTarget.isValid()) {
        setAttribute(QNetworkRequest::RedirectionTargetAttribute, redirectionTarget);
        redirectionRequested(redirectionTarget.toUrl());
    }

    // signal we're open
    metaDataChanged();

    if (operation() == QNetworkAccessManager::GetOperation) {
        QIODevice *contents = nc->data(url());
        if (!contents)
            return false;
        contents->setParent(this);
        writeDownstreamData(contents);
    }

#if defined(QNETWORKACCESSCACHEBACKEND_DEBUG)
    qDebug() << "Successfully sent cache:" << url();
#endif
    return true;
}
开发者ID:wpbest,项目名称:copperspice,代码行数:50,代码来源:qnetworkaccesscachebackend.cpp

示例3: httpFinished

void HttpWindow::httpFinished()
{
    if (httpRequestAborted) {
        if (file) {
            file->close();
            file->remove();
            delete file;
            file = 0;
        }
        reply->deleteLater();
        progressDialog->hide();
        return;
    }

    progressDialog->hide();
    file->flush();
    file->close();


    QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
    if (reply->error()) {
        file->remove();
        QMessageBox::information(this, tr("HTTP"),
                                 tr("Download failed: %1.")
                                 .arg(reply->errorString()));
        downloadButton->setEnabled(true);
    } else if (!redirectionTarget.isNull()) {        
        QUrl newUrl = url.resolved(redirectionTarget.toUrl());
        if (QMessageBox::question(this, tr("HTTP"),
                                  tr("Redirect to %1 ?").arg(newUrl.toString()),
                                  QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
            url = newUrl;
            reply->deleteLater();
            file->open(QIODevice::WriteOnly);
            file->resize(0);
            startRequest(url);
            return;
        }
    } else {
        QString fileName = QFileInfo(QUrl(urlLineEdit->text()).path()).fileName();
        statusLabel->setText(tr("Downloaded %1 to current directory.").arg(fileName));
        downloadButton->setEnabled(true);
    }

    reply->deleteLater();
    reply = 0;
    delete file;
    file = 0;
}
开发者ID:Oxel40,项目名称:ev3sources,代码行数:49,代码来源:httpwindow.cpp

示例4: slotListViewActivated

void StartMainPage::slotListViewActivated(const QModelIndex& index)
{
    if (!index.isValid()) {
        return;
    }
    QVariant data = index.data(KFilePlacesModel::UrlRole);
    KUrl url = data.toUrl();

    // Prevent dir lister error
    if (!url.isValid()) {
        kError() << "Tried to open an invalid url";
        return;
    }
    emit urlSelected(url);
}
开发者ID:,项目名称:,代码行数:15,代码来源:

示例5: metaDataChanged

void DownloadItem::metaDataChanged()
{
    QVariant locationHeader = m_reply->header(QNetworkRequest::LocationHeader);
    if (locationHeader.isValid()) {
        m_url = locationHeader.toUrl();
        m_reply->deleteLater();
        m_reply = BrowserApplication::networkAccessManager()->get(QNetworkRequest(m_url));
        init();
        return;
    }

#ifdef DOWNLOADMANAGER_DEBUG
    qDebug() << "DownloadItem::" << __FUNCTION__ << "not handled.";
#endif
}
开发者ID:jgehring,项目名称:arora,代码行数:15,代码来源:downloadmanager.cpp

示例6: checkManifest

int Updater::checkManifest()
{
    QUrl baseUrl(MANIFEST_URL);
    QNetworkAccessManager manager;
    QNetworkRequest request = getNetworkRequest(baseUrl);
    QNetworkReply *rep = manager.get(request);

    while(rep->error() == QNetworkReply::NoError && !rep->isFinished())
        QCoreApplication::processEvents();

    while(true)
    {
        while(!rep->isFinished())
            QCoreApplication::processEvents();

        if(rep->error() != QNetworkReply::NoError)
            return RES_CHECK_FAILED;

        QVariant redirect = rep->attribute(QNetworkRequest::RedirectionTargetAttribute);
        if(redirect.type() != QVariant::Url)
            break;

        // redirect
        baseUrl = baseUrl.resolved(redirect.toUrl());
        request = getNetworkRequest(baseUrl);
        rep = manager.get(request);
    }

    if(rep->isFinished() && rep->size() != 0)
    {
        QString s;
        QString ver(VERSION);
        while(!rep->atEnd())
        {
            s = rep->readLine();

            QStringList parts = s.split(' ', QString::SkipEmptyParts);
            if(parts.size() < 3 || !ver.contains(parts[0]))
                continue;

            if(REVISION < parts[1].toInt())
                return RES_UPDATE_AVAILABLE;
            else
                return RES_NO_UPDATE;
        }
    }
    return RES_NO_UPDATE;
}
开发者ID:dimitarm1,项目名称:Lorris,代码行数:48,代码来源:updater.cpp

示例7: hasRedirect

 bool DownloadManager::hasRedirect( QNetworkReply *reply )
 {
     if( reply->error() == QNetworkReply::NoError ){
         QVariant redirect = reply->attribute( QNetworkRequest::RedirectionTargetAttribute );
         if( !redirect.isNull() ){
             QUrl originalUrl = reply->request().url();
             QString newUrl = originalUrl.resolved( redirect.toUrl() ).toString();
             stopDownload( originalUrl.toString() );
             startDownload( newUrl );
             return true;
         } else {
             return false;
         }
     }
     return false;
 }
开发者ID:iamOgunyinka,项目名称:PurpleMobile,代码行数:16,代码来源:DownloadManager.cpp

示例8: QVariant

void KDUpdater::HttpDownloader::httpReqFinished()
{
    const QVariant redirect = d->http == 0 ? QVariant() : d->http->attribute( QNetworkRequest::RedirectionTargetAttribute );
    const QUrl redirectUrl = redirect.toUrl();

    if ( followRedirects() && redirectUrl.isValid() )
    {
        if ( d->redirectList.contains( redirectUrl.toString() ) )
        {
            // redirected in an infinte loop or no new url thats an error
            d->destination->remove();
            setDownloadAborted( tr( "Not Found" ) );
        }
        else
        {
            d->redirectList.push_back( redirectUrl.toString() );
            // clean the previous download
            d->http->deleteLater();
            d->http = 0;
            d->destination->close();
            d->destination->deleteLater();
            d->destination = 0;

            d->http = d->manager.get( QNetworkRequest( redirectUrl ) );

            connect( d->http, SIGNAL(readyRead()), this, SLOT(httpReadyRead()) );
            connect( d->http, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(httpReadProgress(qint64,qint64)) );
            connect( d->http, SIGNAL(finished()), this, SLOT(httpReqFinished()) );
            connect( d->http, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(httpError(QNetworkReply::NetworkError)) );

            // Begin the download
            d->destination = new QTemporaryFile(this);
            d->destination->open(); //PENDING handle error
        }
    }
    else
    {
        if( d->http == 0 )
            return;
        httpReadyRead();
        d->destination->flush();
        setDownloadCompleted( d->destination->fileName() );
        d->http->deleteLater();
        d->http = 0;
    }
}
开发者ID:dbzhang800,项目名称:KDUpdater,代码行数:46,代码来源:kdupdaterfiledownloader.cpp

示例9: displayText

QString NativeSeparatorsDelegate::displayText(const QVariant& value, const QLocale&) const {
  const QString string_value = value.toString();

  QUrl url;
  if (value.type() == QVariant::Url) {
    url = value.toUrl();
  } else if (string_value.contains("://")) {
    url = QUrl::fromEncoded(string_value.toAscii());
  } else {
    return QDir::toNativeSeparators(string_value);
  }

  if (url.scheme() == "file") {
    return QDir::toNativeSeparators(url.toLocalFile());
  }
  return string_value;
}
开发者ID:BrummbQ,项目名称:Clementine,代码行数:17,代码来源:playlistdelegates.cpp

示例10: fixResourcePaths

QVariant ObjectNodeInstance::fixResourcePaths(const QVariant &value)
{
    if (value.type() == QVariant::Url)
    {
        const QUrl url = value.toUrl();
        if (url.scheme() == QLatin1String("qrc")) {
            const QString path = QLatin1String("qrc:") +  url.path();
            QString qrcSearchPath = qgetenv("QMLDESIGNER_RC_PATHS");
            if (!qrcSearchPath.isEmpty()) {
                const QStringList searchPaths = qrcSearchPath.split(QLatin1Char(';'));
                foreach (const QString &qrcPath, searchPaths) {
                    const QStringList qrcDefintion = qrcPath.split(QLatin1Char('='));
                    if (qrcDefintion.count() == 2) {
                        QString fixedPath = path;
                        fixedPath.replace(QLatin1String("qrc:") + qrcDefintion.first(), qrcDefintion.last() + QLatin1Char('/'));
                        if (QFileInfo(fixedPath).exists()) {
                            fixedPath.replace(QLatin1String("//"), QLatin1String("/"));
                            fixedPath.replace(QLatin1Char('\\'), QLatin1Char('/'));
                            return QUrl(fixedPath);
                        }
                    }
                }
            }
        }
    }
    if (value.type() == QVariant::String) {
        const QString str = value.toString();
        if (str.contains(QLatin1String("qrc:"))) {
            QString qrcSearchPath = qgetenv("QMLDESIGNER_RC_PATHS");
            if (!qrcSearchPath.isEmpty()) {
                const QStringList searchPaths = qrcSearchPath.split(QLatin1Char(';'));
                foreach (const QString &qrcPath, searchPaths) {
                    const QStringList qrcDefintion = qrcPath.split(QLatin1Char('='));
                    if (qrcDefintion.count() == 2) {
                        QString fixedPath = str;
                        fixedPath.replace(QLatin1String("qrc:") + qrcDefintion.first(), qrcDefintion.last() + QLatin1Char('/'));
                        if (QFileInfo(fixedPath).exists()) {
                            fixedPath.replace(QLatin1String("//"), QLatin1String("/"));
                            fixedPath.replace(QLatin1Char('\\'), QLatin1Char('/'));
                            return fixedPath;
                        }
                    }
                }
            }
        }
    }
开发者ID:MECTsrl,项目名称:imx_mect,代码行数:46,代码来源:objectnodeinstance.cpp

示例11: url

/*!
    Returns an icon URL according to the given \a size.

    If no manager has been assigned to the icon, and the parameters do not contain the QPlaceIcon::SingleUrl key, a default constructed QUrl
    is returned.
*/
QUrl QPlaceIcon::url(const QSize &size) const
{
    if (d->parameters.contains(QPlaceIcon::SingleUrl)) {
        QVariant value = d->parameters.value(QPlaceIcon::SingleUrl);
        if (value.type() == QVariant::Url)
            return value.toUrl();
        else if (value.type() == QVariant::String)
            return QUrl::fromUserInput(value.toString());

        return QUrl();
    }

    if (!d->manager)
        return QUrl();

    return d->manager->d->constructIconUrl(*this, size);
}
开发者ID:venkatarajasekhar,项目名称:Qt,代码行数:23,代码来源:qplaceicon.cpp

示例12: ExtractSong

Song SoundCloudService::ExtractSong(const QVariantMap& result_song) {
  Song song;
  if (!result_song.isEmpty() && result_song["streamable"].toBool()) {
    QUrl stream_url = result_song["stream_url"].toUrl();
    stream_url.addQueryItem("client_id", kApiClientId);
    song.set_url(stream_url);

    QString username = result_song["user"].toMap()["username"].toString();
    // We don't have a real artist name, but username is the most similar thing
    // we have
    song.set_artist(username);

    QString title = result_song["title"].toString();
    song.set_title(title);

    QString genre = result_song["genre"].toString();
    song.set_genre(genre);

    float bpm = result_song["bpm"].toFloat();
    song.set_bpm(bpm);

    QVariant cover = result_song["artwork_url"];
    if (cover.isValid()) {
      // SoundCloud covers URL are https, but our cover loader doesn't seem to
      // deal well with https URL. Anyway, we don't need a secure connection to
      // get a cover image.
      QUrl cover_url = cover.toUrl();
      cover_url.setScheme("http");
      song.set_art_automatic(cover_url.toEncoded());
    }

    int playcount = result_song["playback_count"].toInt();
    song.set_playcount(playcount);

    int year = result_song["release_year"].toInt();
    song.set_year(year);

    QVariant q_duration = result_song["duration"];
    quint64 duration = q_duration.toULongLong() * kNsecPerMsec;
    song.set_length_nanosec(duration);

    song.set_valid(true);
  }
  return song;
}
开发者ID:Skengrobot,项目名称:Clementine,代码行数:45,代码来源:soundcloudservice.cpp

示例13: downloadDefinitions

void ManageDefinitionsDialog::downloadDefinitions()
{
    if (Manager::instance()->isDownloadingDefinitions()) {
        QMessageBox::information(
            this,
            tr("Download Information"),
            tr("There is already one download in progress. Please wait until it is finished."));
        return;
    }

    QList<QUrl> urls;
    foreach (const QModelIndex &index, ui.definitionsTable->selectionModel()->selectedRows()) {
        const QVariant url = ui.definitionsTable->item(index.row(), 0)->data(Qt::UserRole);
        urls.append(url.toUrl());
    }
    Manager::instance()->downloadDefinitions(urls, m_path);
    accept();
}
开发者ID:AgnosticPope,项目名称:qt-creator,代码行数:18,代码来源:managedefinitionsdialog.cpp

示例14: checkReply

void DefinitionUpdater::checkReply() {
  // check for server side redirection
  QVariant redir = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
  if (!redir.isNull()) {
    reply->deleteLater();
    // start update again with redirected URL
    url = redir.toUrl();
    update();
    return;
  }
  // final URL found -> get data
  reply->deleteLater();
  reply = qnam.get(QNetworkRequest(url));
  connect(reply, SIGNAL(finished()),
          this, SLOT(finishUpdate()));
  connect(reply, SIGNAL(readyRead()),
          this, SLOT(checkVersion()));
}
开发者ID:,项目名称:,代码行数:18,代码来源:

示例15: onFinished

void QgsFileDownloader::onFinished()
{
  // when canceled
  if ( ! mErrors.isEmpty() || mDownloadCanceled )
  {
    mFile.close();
    mFile.remove();
    if ( mGuiNotificationsEnabled )
      mProgressDialog->hide();
  }
  else
  {
    // download finished normally
    if ( mGuiNotificationsEnabled )
      mProgressDialog->hide();
    mFile.flush();
    mFile.close();

    // get redirection url
    QVariant redirectionTarget = mReply->attribute( QNetworkRequest::RedirectionTargetAttribute );
    if ( mReply->error() )
    {
      mFile.remove();
      error( tr( "Download failed: %1" ).arg( mReply->errorString() ) );
    }
    else if ( !redirectionTarget.isNull() )
    {
      QUrl newUrl = mUrl.resolved( redirectionTarget.toUrl() );
      mUrl = newUrl;
      mReply->deleteLater();
      mFile.open( QIODevice::WriteOnly );
      mFile.resize( 0 );
      mFile.close();
      startDownload();
      return;
    }
    else
    {
      emit downloadCompleted();
    }
  }
  emit downloadExited();
  this->deleteLater();
}
开发者ID:wongjimsan,项目名称:QGIS,代码行数:44,代码来源:qgsfiledownloader.cpp


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