本文整理汇总了C++中QNetworkReply::isReadable方法的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkReply::isReadable方法的具体用法?C++ QNetworkReply::isReadable怎么用?C++ QNetworkReply::isReadable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QNetworkReply
的用法示例。
在下文中一共展示了QNetworkReply::isReadable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isReadable
bool QNetworkReplyProto::isReadable() const
{
QNetworkReply *item = qscriptvalue_cast<QNetworkReply*>(thisObject());
if (item)
return item->isReadable();
return false;
}
示例2: httpUpdateDownloadFinished
void FvUpdater::httpUpdateDownloadFinished()
{
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
if(reply==NULL)
{
qWarning()<<"The slot httpUpdateDownloadFinished() should only be invoked by S&S.";
return;
}
if(reply->error() == QNetworkReply::NoError)
{
int httpstatuscode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toUInt();
// no error received?
if (reply->error() == QNetworkReply::NoError)
{
if (reply->isReadable())
{
#ifdef Q_OS_MAC
CFURLRef appURLRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
char path[PATH_MAX];
if (!CFURLGetFileSystemRepresentation(appURLRef, TRUE, (UInt8 *)path, PATH_MAX)) {
// error!
}
CFRelease(appURLRef);
QString filePath = QString(path);
QString rootDirectory = filePath.left(filePath.lastIndexOf("/"));
#else
QString rootDirectory = QCoreApplication::applicationDirPath() + "/";
#endif
// Write download into File
QFileInfo fileInfo=reply->url().path();
QString fileName = rootDirectory + fileInfo.fileName();
//qDebug()<<"Writing downloaded file into "<<fileName;
QFile file(fileName);
file.open(QIODevice::WriteOnly);
file.write(reply->readAll());
file.close();
// Retrieve List of updated files (Placed in an extra scope to avoid QuaZIP handles the archive permanently and thus avoids the deletion.)
{
QuaZip zip(fileName);
if (!zip.open(QuaZip::mdUnzip)) {
qWarning("testRead(): zip.open(): %d", zip.getZipError());
return;
}
zip.setFileNameCodec("IBM866");
QList<QuaZipFileInfo> updateFiles = zip.getFileInfoList();
// Rename all current files with available update.
for (int i=0;i<updateFiles.size();i++)
{
QString sourceFilePath = rootDirectory + "\\" + updateFiles[i].name;
QDir appDir( QCoreApplication::applicationDirPath() );
QFileInfo file( sourceFilePath );
if(file.exists())
{
//qDebug()<<tr("Moving file %1 to %2").arg(sourceFilePath).arg(sourceFilePath+".oldversion");
appDir.rename( sourceFilePath, sourceFilePath+".oldversion" );
}
}
}
// Install updated Files
unzipUpdate(fileName, rootDirectory);
// Delete update archive
while(QFile::remove(fileName) )
{
};
// Restart ap to clean up and start usual business
restartApplication();
}
else qDebug()<<"Error: QNetworkReply is not readable!";
}
else
{
qDebug()<<"Download errors ocurred! HTTP Error Code:"<<httpstatuscode;
}
reply->deleteLater();
} // If !reply->error END
} // httpUpdateDownloadFinished END