本文整理汇总了C++中QNetworkReply::size方法的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkReply::size方法的具体用法?C++ QNetworkReply::size怎么用?C++ QNetworkReply::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QNetworkReply
的用法示例。
在下文中一共展示了QNetworkReply::size方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: size
qint64 QNetworkReplyProto::size() const
{
QNetworkReply *item = qscriptvalue_cast<QNetworkReply*>(thisObject());
if (item)
return item->size();
return 0;
}
示例2: 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;
}
示例3: bigRemoteFile
void tst_qhttpnetworkconnection::bigRemoteFile()
{
QNetworkAccessManager manager;
qint64 size;
QTime t;
QNetworkRequest request(QUrl("http://nds1.nokia.com/files/support/global/phones/software/Nokia_Ovi_Suite_webinstaller.exe"));
QNetworkReply* reply = manager.get(request);
connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection);
qDebug() << "Starting download";
t.start();
QTestEventLoop::instance().enterLoop(50);
QVERIFY(!QTestEventLoop::instance().timeout());
size = reply->size();
delete reply;
qDebug() << "Finished!" << endl;
qDebug() << "Time:" << t.elapsed() << "msec";
qDebug() << "Bytes:" << size;
qDebug() << "Speed:" << (size / 1024) / (t.elapsed() / 1000) << "KB/sec";
}
示例4: bigRemoteFile
void tst_qhttpnetworkconnection::bigRemoteFile()
{
QNetworkAccessManager manager;
qint64 size;
QTime t;
QNetworkRequest request(QUrl(QString::fromLatin1(urlC)));
QNetworkReply* reply = manager.get(request);
connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection);
qDebug() << "Starting download" << urlC;
t.start();
QTestEventLoop::instance().enterLoop(50);
QVERIFY(!QTestEventLoop::instance().timeout());
size = reply->size();
delete reply;
qDebug() << "Finished!" << endl;
qDebug() << "Time:" << t.elapsed() << "msec";
qDebug() << "Bytes:" << size;
qDebug() << "Speed:" << (size / qreal(1024)) / (t.elapsed() / qreal(1000)) << "KB/sec";
}
示例5: onDownloadProgress
void DownloadTask::onDownloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{
qDebug() << QString(__FUNCTION__) << " bytesReceived:" << bytesReceived << " , bytesTotal:" << bytesTotal;
QNetworkReply *reply = reinterpret_cast<QNetworkReply*>(sender());
if (reply->error() != QNetworkReply::NoError)
{
qDebug() << QString(__FUNCTION__) << " " << __LINE__ << " error : " << reply->error();
return;
}
qint64 bytesWritten = 0;
if (infoFile_.size() == 0)
{
size_ = reply->header(QNetworkRequest::ContentLengthHeader).toLongLong();
taskFile_.setFileName(taskFileFullName());
//if inf file doesnt exist, task file has to be truncated.
if (!taskFile_.open(QFile::ReadWrite | QFile::Truncate))
{
qDebug() << QString(__FUNCTION__) << " " << __LINE__ << " error : " << taskFile_.error();
return;
}
if (!taskFile_.resize(size_))
{
qDebug() << QString(__FUNCTION__) << " " << __LINE__ << " error : " << taskFile_.error();
return;
}
bytesWritten = infoFile_.write((char*)&size_, sizeof(size_));
if (bytesWritten != sizeof(size_))
{
qDebug() << QString(__FUNCTION__) << " " << __LINE__ << " error : " << infoFile_.error();
return;
}
bytesWritten = infoFile_.write((char*)&progress_, sizeof(progress_));
if (bytesWritten != sizeof(progress_))
{
qDebug() << QString(__FUNCTION__) << " " << __LINE__ << " error : " << infoFile_.error();
return;
}
auto urlBytes = url_.toUtf8();
bytesWritten = infoFile_.write(urlBytes);
if (bytesWritten != urlBytes.size())
{
qDebug() << QString(__FUNCTION__) << " " << __LINE__ << " error : " << infoFile_.error();
return;
}
}
if (!taskFile_.isOpen())
{
taskFile_.setFileName(taskFileFullName());
if (!taskFile_.open(QFile::ReadWrite))
{
qDebug() << QString(__FUNCTION__) << " " << __LINE__ << " error : " << taskFile_.error();
return;
}
}
if (!taskFile_.seek(progress_))
{
qDebug() << QString(__FUNCTION__) << " " << __LINE__ << " error : " << taskFile_.error();
return;
}
qint64 size = reply->size();
bytesWritten = taskFile_.write(reply->readAll());
if (bytesWritten != size)
{
qDebug() << QString(__FUNCTION__) << " " << __LINE__ << " error : " << taskFile_.error();
return;
}
progress_ += size;
if (!infoFile_.seek(sizeof(size_)))
{
qDebug() << QString(__FUNCTION__) << " " << __LINE__ << " error : " << infoFile_.error();
return;
}
bytesWritten = infoFile_.write((char*)&progress_, sizeof(progress_));
if (bytesWritten != sizeof(progress_))
{
qDebug() << QString(__FUNCTION__) << " " << __LINE__ << " error : " << infoFile_.error();
return;
}
speedTest_.downloadBytes_ += size;
qint64 currentMsecs = QDateTime::currentMSecsSinceEpoch();
qint64 timeSpan = currentMsecs - speedTest_.lastMSecsSinceEpoch_;
qint64 bytesPerSecond = 0;
if (timeSpan > 50) //每50ms通知一次UI
{
bytesPerSecond = speedTest_.bytesPerSecond(currentMsecs);
emit downloadProgress(progress_, size_, bytesPerSecond);
qDebug() << "kbytes per second : " << bytesPerSecond / 1024.0f << " timespan : " << timeSpan;
}
if (state_ == Pause || state_ == Cancel)
{
reply->deleteLater();
if (state_ == Cancel)
{
infoFile_.remove();
taskFile_.remove();
}
}
}