c++ - QNetworkAccessManager uploadProgress and QProgressBar -
c++ - QNetworkAccessManager uploadProgress and QProgressBar -
this question has reply here:
calculating percent done progress dialog 3 answersi have qt programme uploads set of files via http post using qnetworkaccessmanager. uploads fine, i'm having problem connecting uploadprogress progressbar.
this code uploading:
class="lang-cpp prettyprint-override">qnetworkaccessmanager *networkmanager = new qnetworkaccessmanager(this); while (numnetconn > 3) { qdebug("waiting number of transfers decrease. [%d]", numnetconn); qtest::qwait(500); } qnetworkreply* reply = networkmanager->post(request, multipart); multipart->setparent(reply); // delete multipart reply connect(reply, signal(finished()), this, slot(ongetreply())); connect(reply, signal(uploadprogress(qint64, qint64)), slot(progresschanged(qint64, qint64))); void mainwindow::progresschanged(qint64 a, qint64 b) { if (b > 0) { qdebug() << "uploading " << << "/" << b << "%" << (double)a/(double)b*100.0; ui->progupload->setvalue((a/b)*100); qapp->processevents(); } } the debug window happily shows lots of progress while uploading, ui not update until end of upload when jumps 100%.
... uploading 171606016 / 172918683 % 99.2409 uploading 171835392 / 172918683 % 99.3735 uploading 172064768 / 172918683 % 99.5062 uploading 172294144 / 172918683 % 99.6388 uploading 172523520 / 172918683 % 99.7715 uploading 172769280 / 172918683 % 99.9136 uploading 172918683 / 172918683 % 100 what missing progresschanged() function update ui?
your percentage calculation is:
(a/b)*100 a , b both integer types here, until a equals b, a/b evaluates 0.
to behavior want, can multiplication first:
100*a/b you cast integers float or double (as in qdebug statement).
c++ qt
Comments
Post a Comment