QProgressBar上传问题
我首先展示我的代码,然后解释我的问题:
... // 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); }
这就是我在上传文件时尝试更新进度条的方法。问题是,它不会完成这项工作。当它开始上传时,我将进度条的值设置为0,然后(感谢这个槽)它实际上不会显示进度,而是立即跳到100%(甚至在完成上传之前)。
我已经检查了 HTTP 客户端示例,并复制了进度条部分,它用于下载,或多或少与上传相同,但它使用 dataReadProgress 信号(下载所需)并且它有效
完美。
有谁知道如何解决上传这个问题吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您正在使用 QHttp 而不是 QNetworkAccessManager。 QHttp 已弃用,并且存在与进度信号相关的错误。
请查看使用 http://qt.nokia.com/doc/ 4.7-snapshot/qnetworkreply.html#downloadProgress 和 http: //qt.nokia.com/doc/4.7-snapshot/qnetworkreply.html#uploadProgress
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
来自 Qt 文档:
因此,如果
done
(例如)以字节为单位(例如 10 B),而total
以 kBytes(例如 7 kB)为单位,那么total
total <完成
,因此进度条变为 100%From the Qt Doc:
So in case
done
is (for example) in Bytes (say 10 B) andtotal
in kBytes (say 7 kB) thentotal < done
and therefore the progressBar goes to 100%