[Interest] Throttle downloads

Jason Kretzer Jason at gocodigo.com
Tue Dec 29 17:32:49 CET 2015


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
Jason at gocodigo.com<mailto:Jason at gocodigo.com>

"quidquid latine dictum sit altum videtur"

[cid:image001.png at 01D1422B.D14A9D10]


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20151229/110356d6/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 13452 bytes
Desc: image001.png
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20151229/110356d6/attachment.png>


More information about the Interest mailing list