QT Breakpoint Continuation (principle: You need to add the Rang section to the header of the HTTP request to tell the server to start the transfer from that location in the file.) Format bytes Start transfer location)

Source: Internet
Author: User

Function: Save data to the specified path according to a URL address, support the continuation of the breakpoint
Parameters: URL--URL address to be accessed
Savepath--The path to be saved
Downedsize already downloaded size
TotalSize Total File size
Return value: Ture--success false--failure
BOOL HttpGet::D ownfile (const qurl &url,const QString &savepath,int downedsize,int totalsize)
{//Create parent folder
QString Curpath=qapplication::applicationdirpath () + "/files";
if (! Qdir (Curpath). Exists ())
{
Qdir Photodir;
Photodir.mkdir (Curpath);
}
Create sub-folders
if (! Qdir (Savepath). Exists ())
{
Qdir Photodir;
Photodir.mkdir (Savepath);
}
Qnetworkrequest Qheader;
Qheader.seturl (URL);
QString range= "bytes" +qstring::number (downedsize) + "-";//Tell the server to start the transfer from Downedsize
Qheader.setrawheader ("Range", Range.toascii ());

Qnetworkaccessmanager Manager;
Reference http://www.qtforum.org/article/31355/qnetworkaccessmanager-using-custom-headers-to-download-a-file.html
Qeventloop Loop;
Qnetworkreply *reply = manager.get (qnetworkrequest (URL));
Qnetworkreply *reply = Manager.get (Qnetworkrequest (Qheader));
Qobject::connect (reply, SIGNAL (finished ()), &loop, SLOT (Quit ()));
Loop.exec ();
Qfileinfo Fileinfo=url.path ();
QFile file (Savepath+fileinfo.filename ());
File.Open (qiodevice::writeonly);
File.write (Reply->readall ());
Delete reply;
return true;
}

Use

Getter. Downfile (Qurl (FILEURL), QString (Currentpath), 0,filesize);
Qobject::connect (&getter, SIGNAL (finished ()), SLOT (Quit ()));

Breakpoint Continuation principle: You need to add the Rang section in the header of the HTTP request to tell the server to start the transfer from that location in the file. The format is bytes start Transfer location

http://blog.csdn.net/henreash/article/details/7267271

QT Breakpoint Continuation (principle: You need to add the Rang section to the header of the HTTP request to tell the server to start the transfer from that location in the file.) Format bytes Start transfer location)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.