本文整理汇总了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);
}
示例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();
}
示例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;
}
示例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;
}
示例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();
}
示例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));
});
}
示例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() );
}
示例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;
}
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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 );
}
}
示例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;
}
示例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());
}
}
示例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);
}
}