user1111
user1111

Reputation: 91

How to download large file quickly in Qt

How do I download a large file in chunks parallelly in Qt. So that the file download time is reduced.

Upvotes: 5

Views: 5438

Answers (1)

Silas Parker
Silas Parker

Reputation: 8147

Assuming you are using QNetwork and the download is an HTTP GET you will need to do the following:

  1. Use a HEAD request to get the file size (Content-Length) and check the server supports Range requests (Accept-Ranges)
  2. Enable pipelining on the GET requests
  3. Set the Range header based on the size of the content

To enable HTTP pipelining on your requests by setting the HttpPipeliningAllowedAttribute attribute:

QNetworkRequest req(url);
req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);

Set the range headers:

req.setRawHeader("Range", "bytes=0-499");

Upvotes: 14

Related Questions