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


C++ QNetworkReply类代码示例

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


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

示例1: QNetworkAccessManager

void LastFmLoginWidget::getToken()
{
    QNetworkAccessManager *manager = new QNetworkAccessManager();
    QNetworkReply *reply = manager->get(QNetworkRequest(getTokenUrl));
    QEventLoop wait;
    connect(manager,SIGNAL(finished(QNetworkReply*)),&wait,SLOT(quit()));
    connect(manager,SIGNAL(finished(QNetworkReply*)), manager, SLOT(deleteLater()));
    //one take is gonna be 10sec
    QTimer oneTake;
    oneTake.start(10000);
    connect(&oneTake,SIGNAL(timeout()),&wait,SLOT(quit()));
    wait.exec();
    //finally get the reply
    QByteArray byteArrayToken = reply->readAll();
    reply->deleteLater();
    //parse xml response
    QXmlStreamReader xmlReader;
    xmlReader.addData(byteArrayToken);
    while (!(xmlReader.name().toString()=="token"))
        xmlReader.readNext();
    TOKEN = xmlReader.readElementText();
    qDebug()<< TOKEN;
    authUrl = QUrl("http://www.last.fm/api/auth/?api_key=" + API_KEY + "&token=" + TOKEN);
}
开发者ID:imandy420,项目名称:vkdesktopmusicplayer,代码行数:24,代码来源:lastfmloginwidget.cpp

示例2: sender

void QTwitchChat::onSelfLoaded()
{
    QNetworkReply *reply = qobject_cast< QNetworkReply * >( sender() );

    QJsonParseError parseError;
    QJsonDocument jsonDoc;

    jsonDoc = QJsonDocument::fromJson( reply->readAll(), &parseError );

    if( parseError.error == QJsonParseError::NoError )
    {
        if( jsonDoc.isObject() )
        {
            QJsonObject _links = ( jsonDoc.object() )[ "_links" ].toObject() ;

            selfLink_ = _links[ "self" ].toString();
            emotIconsLink_ = _links[ "emoticons" ].toString();
            badgesLink_ = _links[ "badges" ].toString();

            getEmotIcons();
        }
    }
    reply->deleteLater();
}
开发者ID:ChunHungLiu,项目名称:BroChat,代码行数:24,代码来源:qtwitchchat.cpp

示例3: url

// Download a single file
bool Handler::downloadFile(string file)
{
    QNetworkAccessManager m_WebCtrl;
    QUrl url((gitHub + file).c_str());
    QEventLoop loop;
    QNetworkRequest request(url);
    QNetworkReply* reply = m_WebCtrl.get(request);
    connect(reply,SIGNAL(finished()),&loop, SLOT(quit()));
    loop.exec();
    QString fileName = url.toDisplayString().remove(gitHub.c_str());

    QByteArray m_DownloadedData;
    m_DownloadedData = reply->readAll();
    reply->deleteLater();
    if (m_DownloadedData.startsWith("Not Found")) {
        writeLog((fileName + " not found from source.\n").toStdString());
        return false;
    }
    QFile qfile("./" + fileName);
    qfile.open(QIODevice::WriteOnly);
    qfile.write(m_DownloadedData);
    qfile.close();
    return true;
}
开发者ID:Jzmorl,项目名称:opensprinkler,代码行数:25,代码来源:handler.cpp

示例4: QueryPair

BtsApiNotifier *BtsApi::getFolderHosts(const QString &secret)
{
	QueryList ql;

	ql << QueryPair("secret", secret);

	QUrl apiUrl = getApiUrl(p, "get_folder_hosts", ql);

	QNetworkReply *reply = p->nam->get(QNetworkRequest(apiUrl));
	BtsApiNotifier *notifier = new BtsApiNotifier(this);

	connect(reply, &QNetworkReply::finished, [this, reply, notifier, secret]()
	{
		notifier->deleteLater();

		if(checkForError(reply, notifier))
			return;

		QJsonDocument doc = QJsonDocument::fromJson(reply->readAll());

		if(checkForError(doc, notifier))
			return;

		QJsonObject obj = doc.object();
		QJsonArray arr = obj.value("hosts").toArray();
		QStringList res;

		for(const QJsonValue &val: arr)
			res << val.toString();

		emit getFolderHostsResult(res, secret);
		emit notifier->getFolderHostsResult(res, secret);
	});

	return notifier;
}
开发者ID:BtbN,项目名称:btsync-qt,代码行数:36,代码来源:bts_api.cpp

示例5: Q_D

void CommandFileList::queryFinished()
{
    Q_D(CommandFileList);
    tryAutoDelete();
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
    if (!reply)
        return;
    reply->deleteLater();

    if (checkInvalidReplyAndRefreshToken(reply))
        return;

    QVariantMap map;
    if (!parseJsonReply(reply, map))
        return;

    d->files.clear();
    Q_FOREACH (const QVariant& item, map.value("items").toList())
    {
        d->files << FileInfo(item.toMap());
    }

    emitSuccess();
}
开发者ID:danilovsergei,项目名称:keepassx-gdrive,代码行数:24,代码来源:command_file_list.cpp

示例6: Finished

void SpotifyImages::FetchInfo(int id, const Song& metadata) {
  if (metadata.artist().isEmpty()) {
    emit Finished(id);
    return;
  }

  // Fetch artist id.
  QUrl search_url(kSpotifySearchUrl);
  search_url.addQueryItem("q", metadata.artist());
  search_url.addQueryItem("type", "artist");
  search_url.addQueryItem("limit", "1");

  qLog(Debug) << "Fetching artist:" << search_url;

  QNetworkRequest request(search_url);
  QNetworkReply* reply = network_->get(request);
  NewClosure(reply, SIGNAL(finished()), [this, id, reply]() {
    reply->deleteLater();
    QJson::Parser parser;
    QVariantMap result = parser.parse(reply).toMap();
    QVariantMap artists = result["artists"].toMap();
    if (artists.isEmpty()) {
      emit Finished(id);
      return;
    }
    QVariantList items = artists["items"].toList();
    if (items.isEmpty()) {
      emit Finished(id);
      return;
    }
    QVariantMap artist = items.first().toMap();
    QString spotify_uri = artist["uri"].toString();

    FetchImagesForArtist(id, ExtractSpotifyId(spotify_uri));
  });
}
开发者ID:Fat-Zer,项目名称:Clementine,代码行数:36,代码来源:spotifyimages.cpp

示例7: QLatin1String

void PlaylistTest::testStatic1()
{
    DynamicPlaylist::PlaylistParams p;
    p.append( DynamicPlaylist::PlaylistParamData( Echonest::DynamicPlaylist::Artist, QLatin1String( "tallest man on earth" ) ) );
    p.append( DynamicPlaylist::PlaylistParamData( Echonest::DynamicPlaylist::Artist, QLatin1String( "bon iver" ) ) );
    p.append( DynamicPlaylist::PlaylistParamData( Echonest::DynamicPlaylist::Artist, QLatin1String( "mumford and sons" ) ) );
    p.append( DynamicPlaylist::PlaylistParamData( Echonest::DynamicPlaylist::Type, Echonest::DynamicPlaylist::ArtistRadioType ) );
    p.append( DynamicPlaylist::PlaylistParamData( Echonest::DynamicPlaylist::Results, 10 ) );

    QNetworkReply* reply = DynamicPlaylist::staticPlaylist( p );

    qDebug() << reply->url().toString();
    QVERIFY( reply->url().toString() == QLatin1String( "http://developer.echonest.com/api/v4/playlist/static?api_key=JGJCRKWLXLBZIFAZB&format=xml&artist=tallest+man+on+earth&artist=bon+iver&artist=mumford+and+sons&type=artist-radio&results=10" ) );

    QEventLoop loop;
    loop.connect( reply, SIGNAL(finished()), SLOT(quit()) );
    loop.exec();
    SongList songs = DynamicPlaylist::parseStaticPlaylist( reply );

    QVERIFY( songs.size() == 10 );
    Q_FOREACH( const Song& song, songs )
        QVERIFY( !song.id().isEmpty() );

}
开发者ID:xhochy,项目名称:libechonest,代码行数:24,代码来源:PlaylistTest.cpp

示例8: switch

void
MusicBrainzPlugin::notInCacheSlot( InfoStringHash criteria, InfoRequestData requestData )
{
    switch ( requestData.type )
    {
        case InfoArtistReleases:
        {
            QString requestString( "http://musicbrainz.org/ws/2/artist" );
            QUrl url( requestString );
            url.addQueryItem( "query", criteria["artist"] );
            QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
            reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );

            connect( reply, SIGNAL( finished() ), SLOT( artistSearchSlot() ) );
            break;
        }

        case InfoAlbumSongs:
        {
            QString requestString( "http://musicbrainz.org/ws/2/artist" );
            QUrl url( requestString );
            url.addQueryItem( "query", criteria["artist"] );
            QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
            reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );

            connect( reply, SIGNAL( finished() ), SLOT( albumSearchSlot() ) );
            break;
        }

        default:
        {
            Q_ASSERT( false );
            break;
        }
    }
}
开发者ID:demelziraptor,项目名称:tomahawk,代码行数:36,代码来源:MusicBrainzPlugin.cpp

示例9: progress

void OnlineSearchBioRxiv::bibTeXDownloadDone() {
    emit progress(++curStep, numSteps);
    QNetworkReply *reply = static_cast<QNetworkReply *>(sender());

    if (handleErrors(reply)) {
        /// ensure proper treatment of UTF-8 characters
        const QString bibTeXcode = QString::fromUtf8(reply->readAll().constData());

        if (!bibTeXcode.isEmpty()) {
            FileImporterBibTeX importer;
            File *bibtexFile = importer.fromString(bibTeXcode);

            if (bibtexFile != NULL) {
                for (File::ConstIterator it = bibtexFile->constBegin(); it != bibtexFile->constEnd(); ++it) {
                    QSharedPointer<Entry> entry = (*it).dynamicCast<Entry>();
                    publishEntry(entry);
                }

                delete bibtexFile;
            } else {
                qCWarning(LOG_KBIBTEX_NETWORKING) << "No valid BibTeX file results returned on request on" << reply->url().toDisplayString();
            }
        }
    }

    if (d->resultPageUrls.isEmpty())
        stopSearch(resultNoError);
    else {
        const QUrl firstUrl = *d->resultPageUrls.constBegin();
        d->resultPageUrls.remove(firstUrl);
        QNetworkRequest request(firstUrl);
        QNetworkReply *reply = InternalNetworkAccessManager::self()->get(request);
        InternalNetworkAccessManager::self()->setNetworkReplyTimeout(reply);
        connect(reply, &QNetworkReply::finished, this, &OnlineSearchBioRxiv::resultPageDone);
    }
}
开发者ID:KDE,项目名称:kbibtex,代码行数:36,代码来源:onlinesearchbiorxiv.cpp

示例10: handleStreams

void AzubuHandler::handleStreams() {

    QNetworkReply *reply = qobject_cast<QNetworkReply*>(QObject::sender());
    QByteArray data = reply->readAll();

    // delete the reply
    reply->deleteLater();

    QJsonDocument response(QJsonDocument::fromJson(data.mid(1,data.length()-2)));
    QJsonArray streamsArray = response.array();

    for(int i=0; i<streamsArray.size(); ++i) {

        QJsonObject streamJson = streamsArray[i].toObject();
        AzubuStream stream;

        // populate the stream
        stream.read(streamJson);

        // emit signal
        emit addStream(stream);
    }

}
开发者ID:Oyuret,项目名称:liveGUIMobile,代码行数:24,代码来源:azubuhandler.cpp

示例11: aboutToCreateCover

void MusicBrainzProvider::downloadCover(QByteArray ba, QNetworkReply *reply)
{
	QString album = reply->property("album").toString();

	// In case we don't get the picture at the first attempt, try again
	QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
	if (redirectionTarget.isNull()) {

		// The current cover has been downloaded to a temporary location, the lists can be populated
		//QPixmap pixmap;

		// It's possible to have a valid release but without cover yet :(
		//if (pixmap.loadFromData(ba)) {
		//	emit aboutToCreateCover(album, pixmap);
		//}
		emit aboutToCreateCover(album, ba);
	} else {
		QUrl newUrl = reply->url().resolved(redirectionTarget.toUrl());
		QNetworkReply *reply = _manager->get(QNetworkRequest(newUrl));
		reply->setProperty("type", type());
		reply->setProperty("requestType", FO_DownloadCover);
		reply->setProperty("album", album);
	}
}
开发者ID:Ilya87,项目名称:cover-fetcher,代码行数:24,代码来源:musicbrainzprovider.cpp

示例12: sender

void
UpcomingEventsWidget::loadImage()
{
    QNetworkReply *reply = qobject_cast<QNetworkReply*>( sender() );
    if( !reply )
        return;

    reply->deleteLater();
    const KUrl &url = reply->request().url();
    if( m_imageUrl != url )
        return;

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

    QPixmap image;
    if( image.loadFromData( reply->readAll() ) )
    {
        image = image.scaled( 116, 116, Qt::KeepAspectRatio, Qt::SmoothTransformation );
        image = The::svgHandler()->addBordersToPixmap( image, 6, QString(), true );
        QPixmapCache::insert( url.url(), image );
        m_image->setPixmap( image );
    }
}
开发者ID:cancamilo,项目名称:amarok,代码行数:24,代码来源:UpcomingEventsWidget.cpp

示例13: config

void NetworkTaskManager::startDownload( LoadImageTask * task )
{
	IniConfig & ini = config();
	ini.pushSection( "Image_Loading" );
	QString prefix = ini.readString( "HttpUrl" );
	QString user = ini.readString( "HttpUser" );
	QString password = ini.readString( "HttpPassword" );
	ini.popSection();
	
	if( task->mPath[0].isLetter() )
		task->mPath[0] = task->mPath[0].toLower();
	
	QUrl url( prefix + task->mPath.replace(":","").replace("\\","/") );
	LOG_5( "Fetching URL: " + url.toString() );
	QNetworkRequest request(url);
	request.setRawHeader("Authorization", "Basic " + QByteArray(QString("%1:%2").arg(user).arg(password).toAscii()).toBase64()); 
	QNetworkReply * reply = mNetworkAccessManager->get(request);
	reply->setReadBufferSize(0);
	connect( reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(slotError(QNetworkReply::NetworkError)) );
#ifndef QT_NO_OPENSSL
	connect( reply, SIGNAL(sslErrors(const QList<QSslError> &)), SLOT(slotSslErrors(const QList<QSslError> &)) );
#endif
	mReplyDict[reply] = task;
}
开发者ID:EntityFXCode,项目名称:arsenalsuite,代码行数:24,代码来源:imageview.cpp

示例14: reverseGeoLookup

extern "C" void reverseGeoLookup(degrees_t latitude, degrees_t longitude, uint32_t uuid)
{
	QNetworkRequest request;
	QNetworkAccessManager *rgl = new QNetworkAccessManager();
	request.setUrl(QString("http://open.mapquestapi.com/nominatim/v1/reverse.php?format=json&accept-language=%1&lat=%2&lon=%3")
		       .arg(uiLanguage(NULL)).arg(latitude.udeg / 1000000.0).arg(longitude.udeg / 1000000.0));
	request.setRawHeader("Accept", "text/json");
	request.setRawHeader("User-Agent", getUserAgent().toUtf8());
	QNetworkReply *reply = rgl->get(request);
	QEventLoop loop;
	QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
	loop.exec();
	QJsonParseError errorObject;
	QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &errorObject);
	if (errorObject.error != QJsonParseError::NoError) {
		qDebug() << errorObject.errorString();
	} else {
		QJsonObject obj = jsonDoc.object();
		QJsonObject address = obj.value("address").toObject();
		qDebug() << "found country:" << address.value("country").toString();
		struct dive_site *ds = get_dive_site_by_uuid(uuid);
		ds->notes = add_to_string(ds->notes, "countrytag: %s", address.value("country").toString().toUtf8().data());
	}
}
开发者ID:davidromero,项目名称:subsurface,代码行数:24,代码来源:qthelper.cpp

示例15: qDebug

void Pastebin::onSubmitPasteFinished() {
    QNetworkReply *networkReply = qobject_cast<QNetworkReply *>(sender());
    QVariant statusCode = networkReply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    qDebug() << "Paste complete:" << statusCode.toInt();

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

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

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


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