QProgressBar上传问题

发布于 2024-08-27 03:14:58 字数 683 浏览 3 评论 0原文

我首先展示我的代码,然后解释我的问题:

...
// 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

等数载,海棠开 2024-09-03 03:14:58

看起来您正在使用 QHttp 而不是 QNetworkAccessManager。 QHttp 已弃用,并且存在与进度信号相关的错误。

请查看使用 http://qt.nokia.com/doc/ 4.7-snapshot/qnetworkreply.html#downloadProgresshttp: //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

橙幽之幻 2024-09-03 03:14:58

来自 Qt 文档:

警告:完成和总计不是
必然是以字节为单位的大小,因为
对于大文件这些值可能
需要“缩放”以避免溢出。

另请参见 dataReadProgress()、post()、
request() 和 QProgressBar。

因此,如果 done (例如)以字节为单位(例如 10 B),而 total 以 kBytes(例如 7 kB)为单位,那么 total total <完成,因此进度条变为 100%

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%

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文