nreply->readAll()
nreply->readAll()
To copy to clipboard, switch view to plain text mode
This line is throwing an error as below only for windows machine. The same code works fine for mac.
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
The download code is as below
zoushoFtpTransfer :: zoushoFtpTransfer()
{
m_manager = new QNetworkAccessManager();
m_request = new QNetworkRequest;
m_reply = NULL;
m_isDownloadSccess = false;
connect(m_manager, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)),
this, SLOT(handleSslErrors(QNetworkReply*,QList<QSslError>)));
connect(m_manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(replyfinished(QNetworkReply*)));
m_htmlDownloadCount = 0 ;
}
void zoushoFtpTransfer :: downloadFromServer()
{
QNetworkRequest request;
url.setUrl(m_url);
url.setUserName(m_username);
url.setPassword(m_password);
request.setUrl(url);
zoushoConstructFilePath();
zoushoConstructDownloadDir();
zoushoConstructDownloadPath();
m_reply = m_manager->get(request);
}
void zoushoFtpTransfer :: replyfinished(QNetworkReply *nreply)
{
if(nreply->error() )
{
qDebug() << "download failed...." <<nreply->errorString();
m_isDownloadFailure = true;
}
else
{
//m_url = "http://www.ssparkl.com/download.php?filename=fullbook/LifeSciences_Grade10_1947.zip";
if(m_url.endsWith(".zip"))
{
file.write(nreply->readAll());
file.close();
m_isDownloadSccess = true;
return;
}
}
zoushoFtpTransfer :: zoushoFtpTransfer()
{
m_manager = new QNetworkAccessManager();
m_request = new QNetworkRequest;
m_reply = NULL;
m_isDownloadSccess = false;
connect(m_manager, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)),
this, SLOT(handleSslErrors(QNetworkReply*,QList<QSslError>)));
connect(m_manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(replyfinished(QNetworkReply*)));
m_htmlDownloadCount = 0 ;
}
void zoushoFtpTransfer :: downloadFromServer()
{
QNetworkRequest request;
QUrl url;
url.setUrl(m_url);
url.setUserName(m_username);
url.setPassword(m_password);
request.setUrl(url);
zoushoConstructFilePath();
zoushoConstructDownloadDir();
zoushoConstructDownloadPath();
m_reply = m_manager->get(request);
}
void zoushoFtpTransfer :: replyfinished(QNetworkReply *nreply)
{
if(nreply->error() )
{
qDebug() << "download failed...." <<nreply->errorString();
m_isDownloadFailure = true;
}
else
{
//m_url = "http://www.ssparkl.com/download.php?filename=fullbook/LifeSciences_Grade10_1947.zip";
if(m_url.endsWith(".zip"))
{
QFile file(m_localPath);
file.open(QIODevice::WriteOnly);
file.write(nreply->readAll());
file.close();
m_isDownloadSccess = true;
return;
}
}
To copy to clipboard, switch view to plain text mode
The download file size is 318459022.
I checked the received data using the below code and it final received size is 318459022.
connect(m_WebCtrl.get(request), SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadprogress(qint64,qint64)));
connect(m_WebCtrl.get(request), SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadprogress(qint64,qint64)));
To copy to clipboard, switch view to plain text mode
Book with size of 20MB are getting downloaded without issues.
Kindly help me to know, where I am going wrong
Bookmarks