gpt4 book ai didi

c++ - QNetworkAccessManager uploadProgress 和 QProgressBar

转载 作者:太空宇宙 更新时间:2023-11-04 16:14:34 25 4
gpt4 key购买 nike

<分区>

我有一个 QT 程序,它使用 QNetworkAccessManager 通过 Http POST 上传一组文件。一切都可以正常上传,但我无法将 uploadProgress 与进度条连接起来。

这是上传的代码:

QNetworkAccessManager *networkManager = new QNetworkAccessManager(this);
while (numNetConn > 3) {
qDebug("Waiting for the number of transfers to decrease. [%d]", numNetConn);
QTest::qWait(500);
}
QNetworkReply* reply = networkManager->post(request, multiPart);
multiPart->setParent(reply); // delete the multiPart with the 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 " << a << "/" << b << "%" << (double)a/(double)b*100.0;
ui->progUpload->setValue((a/b)*100);
qApp->processEvents();
}
}

调试窗口在上传时愉快地显示了很多进度,但 UI 直到上传结束时跳到 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

我在更新 UI 的 progressChanged() 函数中缺少什么?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com