关键代码
void DownloadTask::StartDownload(const QUrl url,QFile *file,qint64 startPoint/* =0 */,qint64 endPoint/* =-1 */)
{if( NULL == file )return;m_HaveDoneBytes = 0;m_StartPoint = startPoint;m_EndPoint = endPoint;m_File = file;//根据HTTP协议,写入RANGE头部,说明请求文件的范围QNetworkRequest qheader;qheader.setUrl(url);QString range;range.asprintf(";Bytes=%lld-%lld;", m_StartPoint, m_EndPoint);qheader.setRawHeader(";Range", range.toLatin1());//开始下载qDebug() << "Part " << m_Index << "start download";m_Reply = m_Qnam.get(QNetworkRequest(qheader));connect(m_Reply, SIGNAL(finished()),this, SLOT(FinishedSlot()));connect(m_Reply, SIGNAL(readyRead()),this, SLOT(HttpReadyRead()));
}
效果
创作不易,小小的支持一下吧!