QNetworkAccessManager 超时 [英] QNetworkAccessManager timeout
问题描述
目前我正在开发一个从远程服务器发送和接收文件的应用程序.为了进行网络操作,我使用 QNetworkAccessManager.
Presently I am working on an application which sends and receives file from remote server. To do network operation I am using QNetworkAccessManager.
上传文件我使用 QNetworkAccessManager::put() 下载我使用 QNetworkAccessManager::get() 函数.
To upload a file I am using QNetworkAccessManager::put() and to download I am using QNetworkAccessManager::get() functions.
上传文件时,我将初始化一个计时器,超时时间超过 15 秒.如果我上传一个小文件,它将在超时时间内完成.但是,如果我尝试上传非常大的文件,则会超时.那么如何决定上传大文件的超时时间.
While uploading a file I will initialize a timer with time out of 15 sec. if I upload a small file it will complete it within the time out period. But if I try to upload a file which is very large in size get time out. So how to decide time out for uploading of large file.
下载大文件时也是如此.我在 readyread() 信号中逐块获取文件.在这里,如果我下载一个大文件,我也会超时.那么如何决定上传大文件的超时时间.
Same in case of downloading of a large file. I get file in chunk by chunk in readyread() signal. Here also if I download a large file I get time out. So how to decide time out for uploading of large file.
推荐答案
使用 QNetworkReply::uploadProgress()
(或downloadProgress
) 信号,提醒您操作正在进行中.然后,在最后一个 uploadProgress
/downloadProgress
通知后设置一个 15 秒的计时器(在下载/上传开始时启动计时器.)如果下载停止,您可以上次更新后 15 秒取消操作.
Use the QNetworkReply::uploadProgress()
(or downloadProgress
) signal to alert you that the operation is progressing. Then, set a timer for 15 seconds after the last uploadProgress
/downloadProgress
notification (with the timer started when the download/upload commenced.) If the download ever stops, you can cancel the operation 15 seconds after the last update.
这篇关于QNetworkAccessManager 超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!