matt4682
1st May 2014, 22:27
Currently in a project I'm working on I'm using a slightly modified version of this (http://stackoverflow.com/a/6341374) (emits fileSaved() and takes a save path) to download files like so:
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();
}
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
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();
}
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