Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download large file quickly in Qt

Tags:

qt

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

like image 641
user1111 Avatar asked Dec 13 '22 03:12

user1111


1 Answers

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");
like image 107
Silas Parker Avatar answered Jan 06 '23 14:01

Silas Parker