ayanda83
6th January 2017, 06:43
I've got a program that is supposed to download a list of pdf documents from the web using QNetworkAccessManager. I have a QStringList of pdf urls and my problem is getting QNetworkAccessManager to download 6 pdf's at a time, when I try implementing this, the program keeps downloading the first url on the list 6 times. What could be causing this?
void CPT_Page::getPdf(QStringList linksList)
{
qDebug() << linksList <<endl;
for(int i = 0; i < linksList.size(); i++)
{
download_request_list.append(QNetworkRequest(QUrl( QString("http://web1.capetown.gov.za%1").arg(linksList.at(i)))));
download_replies_list.append(nManager->get(download_request_list.at(i)));
connect(download_replies_list.at(i), SIGNAL(finished()), this, SLOT(downloadAttachment()));
}
}
void CPT_Page::downloadAttachment()
{
static int fileNum = 1;
QFile tempFile(QString("C:/Users/C5248134/Desktop/Projects/Ithala/Include/Sourced_Tenders/temp%1.pdf").arg(fileNum));
fileNum++;
if(!tempFile.open(QFile::WriteOnly))
qDebug() << "File did not open" <<endl;
QDataStream outStream(&tempFile);
outStream << download_replies_list.at(0)->readAll() <<endl;
download_replies_list.clear();
}
void CPT_Page::getPdf(QStringList linksList)
{
qDebug() << linksList <<endl;
for(int i = 0; i < linksList.size(); i++)
{
download_request_list.append(QNetworkRequest(QUrl( QString("http://web1.capetown.gov.za%1").arg(linksList.at(i)))));
download_replies_list.append(nManager->get(download_request_list.at(i)));
connect(download_replies_list.at(i), SIGNAL(finished()), this, SLOT(downloadAttachment()));
}
}
void CPT_Page::downloadAttachment()
{
static int fileNum = 1;
QFile tempFile(QString("C:/Users/C5248134/Desktop/Projects/Ithala/Include/Sourced_Tenders/temp%1.pdf").arg(fileNum));
fileNum++;
if(!tempFile.open(QFile::WriteOnly))
qDebug() << "File did not open" <<endl;
QDataStream outStream(&tempFile);
outStream << download_replies_list.at(0)->readAll() <<endl;
download_replies_list.clear();
}