C++ Qt get HTTP headers from QNetworkRequest -


i developing qt c++ application. need download files (which can large) , show downloading progress user. perform task, use code:

qnetworkaccessmanager* networkmanager = new qnetworkaccessmanager();  qnetworkrequest request(fileurl); //fileurl qurl variable qvariant responselength = request.header(qnetworkrequest::contentlengthheader); int filesize = responselength.toint(); ui->progressbar->setmaximum(filesize); qnetworkreply reply = networkmanager->get(request); qobject::connect(reply, signal(downloadprogress(qint64,qint64)),                  this, slot(downloadprogresschanged(qint64,qint64))); 

where downloadprogresschanged slot code:

void downloadprogresschanged(qint64 downloaded, qint64 total) {     ui->progressbar->setvalue(ui->progressbar->value() + 1);     ui->labelprogress->settext(qstring::number((downloaded / 1024))); } 

(i use qprogressbar named progressbar show progress , qlabel named labelprogress show downloaded kilobytes).

my problem can't access content-length header (int filesize value 0) , not able show progress of operation. checked http headers on web-server - content-length works fine.

in this question read can use qnetworkreply::metadatachanged() signal, how can use show progress? documentation says signal can emitted when downloading has been started, need header content before downloading start - set progressbar.

have tried using readyread signal? , in slot prepare gui. shoud work:

connect(reply, signal(readyread()), this, slot(updateprogressbar())) 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -