Currently in a project I'm working on I'm using a slightly modified version of this (emits fileSaved() and takes a save path) to download files like so:
QDownloader *downloader = new QDownloader();
connect(downloader, SIGNAL(fileSaved()), &imageLoop, SLOT(quit()));
for(int i = 0; i < imageURLs.length(); i++) {
progressDialog->setValue((int)(100 * (double)i / imageURLs.length()));
progressDialog
->setLabelText
("Downloading image: " + QString::number(i
+ 1) + "/" + QString::number(imageURLs.
length()));
if(progressDialog->wasCanceled())
break;
downloader
->setFile
(imageURLs.
at(i
),
QDir::homePath() + "/images/" + imageNames.
at(i
) + ".jpg");
imageLoop.exec();
}
QEventLoop imageLoop;
QDownloader *downloader = new QDownloader();
connect(downloader, SIGNAL(fileSaved()), &imageLoop, SLOT(quit()));
for(int i = 0; i < imageURLs.length(); i++) {
progressDialog->setValue((int)(100 * (double)i / imageURLs.length()));
progressDialog->setLabelText("Downloading image: " + QString::number(i + 1) + "/" + QString::number(imageURLs.length()));
if(progressDialog->wasCanceled())
break;
downloader->setFile(imageURLs.at(i), QDir::homePath() + "/images/" + imageNames.at(i) + ".jpg");
imageLoop.exec();
}
To copy to clipboard, switch view to plain text mode
The program crashes sometimes doing this and I was wondering what I am doing wrong or what is a more common or appropriate way to accomplish this.
Thanks
Bookmarks