开发者

QProgressBar problem with uploading

I show my code first, then I explain my problem:

...
// somewhere in the constructor
    progressBar = ne开发者_运维百科w QProgressBar(this);
    progressBar->setMinimum(0);
    progressBar->setMaximum(100);
...
    connect(&http, SIGNAL(dataSendProgress(int, int)), this, SLOT(updateProgressBar(int, int)));
...
void MainWindow::updateProgressBar(int bytesSent, int total)
{
        progressBar->setMaximum(total);
        progressBar->setValue(bytesSent);
}

So this is how I try to make my progressBar being updated when I upload a file. The problem is, it won't do the job. When it starts uploading, I set the value of the progress bar to 0, then (thanks to this slot) it won't actually show the progress, but will jump to 100% immediately (even before it finished uploading).

I already checked the HTTP Client example, and copied the progress bar part, it is for downloading, and more or less is the same as for uploading but it uses the dataReadProgress signal (needed for downloading) AND it works perfectly.

Does anybody know how to solve this for uploading?


It looks like you are using QHttp and not QNetworkAccessManager. QHttp is deprecated and has bugs related to the progress signals.

Please look into using http://qt.nokia.com/doc/4.7-snapshot/qnetworkreply.html#downloadProgress and http://qt.nokia.com/doc/4.7-snapshot/qnetworkreply.html#uploadProgress


From the Qt Doc:

Warning: done and total are not necessarily the size in bytes, since for large files these values might need to be "scaled" to avoid overflow.

See also dataReadProgress(), post(), request(), and QProgressBar.

So in case done is (for example) in Bytes (say 10 B) and total in kBytes (say 7 kB) then total < done and therefore the progressBar goes to 100%

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜