对于使用Qt 5.3.2的旧工具,我们最近遇到了一个问题。使用QNetwork
管理器可以下载文件,但是在下载文件之前,我们先检查是否可以从特定区域下载文件。为此,我们会在第一个进度指示处中止操作。
自最近以来,在某些异常终止后,我们不再收到downloadProgress
信号,并且仅在非常快速的网络连接中发生。通过WiFi无法复制。可能是什么问题?
一些代码段:
开始下载:
networkManager->get(request);
networkReply->setReadBufferSize(4 * 1024 * 1024);
connect(networkReply, SIGNAL(finished()),
this, SLOT(onDownloadFinished()));
connect(networkReply, SIGNAL(downloadProgress(qint64, qint64)),
this, SLOT(onDownloadProgress()));
connect(networkReply, SIGNAL(error(QNetworkReply::NetworkError)),
this, SLOT(onDownloadError(QNetworkReply::NetworkError)));
connect(networkReply, SIGNAL(sslErrors(QList<QSslError>)),
this, SLOT(onDownloadSslErrors(QList<QSslError>)));
connect(networkReply, SIGNAL(encrypted()),
this, SLOT(onEncrypted()));
OnDownloadProgress:
void DownloadManager::onDownloadProgress()
{
networkReply->abort();
nrAborts++;
startDownload(myurl);
}
OnDownloadFinished:
void DownloadManager::onDownloadFinished()
{
networkReply->deleteLater();
}
答案 0 :(得分:2)
由于读取缓冲区在第一个onDownloadProgress
之前已满,并且从未读取过,因此全部卡住了。订阅readyRead
并用networkReply->readAll()
读取数据将导致缓冲区被刷新并调用downloadProgress
信号。