From: "Jason Kretzer" <ja...@gocodigo.com>
To: "interest@qt-project.org" <interest@qt-project.org>
Subject: [Interest] Throttle downloads
Hello all,
I have an application that must download files in the background. I separate this process off into a separate thread so that it does not interfere with the UI. Unfortunately, when it starts downloading, it uses the full pipe that it has access to and adversely affects the rest of the network – causing other internet connections to slow to a crawl. The application is installed on networks which I do not control and cannot throttle it that way. What I would like to do is have the application not eat so much bandwidth during the download.
The code I am using to download is pretty run of the mill (error checks removed for brevity):
void ContentDownloader::downloadFile(QUrl url, QString filename)
{
QNetworkRequest request(url);
QNetworkAccessManager* _manager = new QNetworkAccessManager(this);
QNetworkReply* reply = _manager->get(request);
QEventLoop loop;
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
QFile file(filename);
file.open(QIODevice::WriteOnly);
file.write(reply->readAll());
file.close();
}
Thoughts on how to make it “slow down”? I have been toying with the setReadBufferSize in the reply but does not really seem to change anything.
Thanks!
-Jason
- - - - - - - - - - - - - - - - - - - - - - -
Jason R. Kretzer
Lead Application Developer
“quidquid latine dictum sit altum videtur”
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest