顺序中止后未触发Qt下载进度

时间:2018-07-06 10:19:24

标签: c++ qt network-programming

对于使用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();
}

1 个答案:

答案 0 :(得分:2)

由于读取缓冲区在第一个onDownloadProgress之前已满,并且从未读取过,因此全部卡住了。订阅readyRead并用networkReply->readAll()读取数据将导致缓冲区被刷新并调用downloadProgress信号。