Wednesday, May 5, 2010

Simple download manager in Qt with puase/ resume support

Update: Here is link to my full working code sample.

Recently I needed to create simple download manager that support pause/ resume.

I was using Qt's network module (QNetworkAccessManager to be specific) to download media content, but QNetworkAccessManager class by itself does not support pause/resume feature.

But with little effort we can make it to support pause/resume. Trick it to set "Range" header while making HTTP request.

Please visit RFC 2616 for more information related to Range header.

To implement download manager, I have used example code from Qt 4.6 ( and then added code to support pause and resume.

In my code when user pause download I am saving current request and on resume I am adding Range header to saved request then starting download using that saved request.

downloadSizeAtPause = _currentRequest->_device->size();
QByteArray rangeHeaderValue = "bytes=" + QByteArray::number(downloadSizeAtPause) + "-"; 



So here is simple download manager.



  1. could explain more how work this code?, I don´t understand what's "downloadSizeAtPause" or "setRawHeader"

  2. downloadSizeAtPause is just int variable to get current download size when item was paused.

    setRawHeader is Qt API to set HTTP Header.

  3. ok thanks!, excuse me for other question: how I can restart the download using a Range header?, I'm searching but I don't found any function that make this or maybe I don't see it.

  4. Hi,
    here _currentRequest->_request is QNetworkRequest

    and by following statement you are setting range header on QNetworkRequest.


    After setting range header, you can use get method of QNetworkAccessManager with this QNetworkRequest to restart your paused download.

  5. thanks!!!

    very usefull.

    NEMO, from Costa Rica

  6. Hi Kunal,

    I have added your code in download manager example, however It still not working. Might you send me your code.

    Thank you very much!

  7. Hi,
    I will try to provide working sample code asap.

  8. Hi,
    code is uploaded here.

    Thanks for visiting my blog. Hope you find above information useful.


  9. Hi Kunal,

    Thank you very much! I got your code already.It's very helpful. I am going to implement a upload manager with pause/resume. If I get problems, hope you help me.

    Best regards,

  10. heu kunal:
    can this be used for any type of files zip tar.gz i mean binaries

  11. yes, it should work with any kind of file. As you see in video, I am downloading and exe file.

    1. thanks man for replying are u intrested in working in a download manager

    2. I did not get you question clearly ?

  12. i am working in a download manager are you intrested in joining that project

  13. I am sorry, But I think I will not be able to commit enough time for your project. Thanks for your offer :)

  14. Note the number of bytes returned by QIODevice.size() may not represent the actual bytes transmitted ,The reason for this is that there may be protocol overhead or the data may be compressed during the download.