{
qb.setWindowTitle("Download in Progress");
progressDialog
= new QProgressDialog("Preparing to Download",
"Cancel",
0,
100);
progressDialog->setWindowTitle("Downloading");
progressDialog->show();
QNetworkAccessManager *m_WebCtrl = new QNetworkAccessManager(this);
setFilePath(zipFilePath);
file.setFileName(this->getFilePath());
downloadedDataSize = 0;
QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
reply = m_WebCtrl->get(request);
connect(reply,SIGNAL(readyRead()),this,SLOT(slotReadData()));
connect(reply,SIGNAL(finished()), this,SLOT(fileDownloaded()));
connect(reply, SIGNAL(downloadProgress(qint64,qint64)),this, SLOT(downloadprogress(qint64,qint64)));
}
void bookdownloader::fileDownloaded()
{
progressDialog->close();
emit downloaded();
}
void bookdownloader::downloadprogress(qint64 recieved, qint64 total)
{
if(total < 1)
return;
progressDialog->setValue((recieved*100/total));
if (progressDialog->wasCanceled())
{
progressDialog->close();
m_WebCtrl->blockSignals(true);
}
progressDialog
->setLabelText
(QString::number((recieved
*100/total
))+"%");
}
void bookdownloader::slotReadData()
{
file.setFileName(this->getFilePath());
{
QMessageBox::critical(NULL,
"Hello!",
"Error saving file!");
return;
}
out << reply->readAll();
file.close();
downloadedDataSize += file.size();
}
bookdownloader::bookdownloader(QUrl url, QObject *parent,QString zipFilePath) : QObject(parent)
{
qb.setWindowTitle("Download in Progress");
progressDialog = new QProgressDialog("Preparing to Download", "Cancel", 0, 100);
progressDialog->setWindowTitle("Downloading");
progressDialog->show();
QNetworkAccessManager *m_WebCtrl = new QNetworkAccessManager(this);
setFilePath(zipFilePath);
file.setFileName(this->getFilePath());
downloadedDataSize = 0;
QByteArray postData;
QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
reply = m_WebCtrl->get(request);
connect(reply,SIGNAL(readyRead()),this,SLOT(slotReadData()));
connect(reply,SIGNAL(finished()), this,SLOT(fileDownloaded()));
connect(reply, SIGNAL(downloadProgress(qint64,qint64)),this, SLOT(downloadprogress(qint64,qint64)));
}
void bookdownloader::fileDownloaded()
{
progressDialog->close();
emit downloaded();
}
void bookdownloader::downloadprogress(qint64 recieved, qint64 total)
{
if(total < 1)
return;
progressDialog->setValue((recieved*100/total));
if (progressDialog->wasCanceled())
{
progressDialog->close();
m_WebCtrl->blockSignals(true);
}
progressDialog->setLabelText(QString::number((recieved*100/total))+"%");
}
void bookdownloader::slotReadData()
{
file.setFileName(this->getFilePath());
if(!file.open(QIODevice::WriteOnly| QIODevice::Append))
{
QMessageBox::critical(NULL,"Hello!","Error saving file!");
return;
}
QDataStream out(&file);
out << reply->readAll();
file.close();
downloadedDataSize += file.size();
}
To copy to clipboard, switch view to plain text mode
void bookdownloader::slotReadData()
{
file.setFileName(this->getFilePath());
file.write(reply->read(reply->bytesAvailable()));
file.close();
}
void bookdownloader::slotReadData()
{
file.setFileName(this->getFilePath());
file.open(QIODevice::Append);
file.write(reply->read(reply->bytesAvailable()));
file.close();
}
To copy to clipboard, switch view to plain text mode
Bookmarks