0
votes

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

...
// somewhere in the constructor
    progressBar = new 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?

2
Are you performing the upload in a separate thread? If you are performing the upload in the GUI thread, the progress bar may not be updated since the thread is blocked.Jason B

2 Answers

1
votes

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

0
votes

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%