QNetworkReply do not have any progress(no reply from server), how should I deal with it?



  • Qt5.6.2
    compiler : msvc 2015 64bits

    Trying to scrape images from google search, after I obtain all of the links of the images and start to download them, sometimes servers take a long time to respond or even "refuse" to response, in that case, the app will hang at there unless I setup a timer to monitor the progress of network reply as before(if it takes too long to reply, restart the download or abort it). This solution got a problem ,I have to setup the waiting time manually, and I have no idea how many seconds I should wait because I have no control on different environments.

    I start the download like this

    task->network_reply_ = network_access_->get(task->network_request_);
    connect(task->network_reply_, static_cast<void(QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error), this, &download_supervisor::error_handle);
    connect(task->network_reply_, &QNetworkReply::readyRead, this, &download_supervisor::ready_read);
    connect(task->network_reply_, static_cast<void(QNetworkReply::*)()>(&QNetworkReply::finished), this, &download_supervisor::process_download_finished);
    connect(task->network_reply_, &QNetworkReply::downloadProgress, this,&download_supervisor::handle_download_progress);
    connect(task->network_reply_, static_cast<void(QNetworkReply::*)()>(&QNetworkReply::finished),task->network_reply_, &QNetworkReply::deleteLater);
    

    Network request similar to

    QNetworkRequest request(url);
    QString const header = "Googlebot-Image/1.0";
    request.setHeader(QNetworkRequest::UserAgentHeader, header);
    

    By the way, whole project place at github, I always want an app to help me download the images by google, bing, flickr search for computer vision projects.


  • Lifetime Qt Champion

    Hi,

    Sounds like you should gather some statistics about the timeout you experience from your machine and then try to calculate a good values to use.



  • Hi..
    My suggestion in this is, By using QTimer you can overcome from your issue.
    take a Qtimer instance set some certain interval, after the request start the timer and once the timer emits timeout connect it to another slot and check the reply came or not(do it for some time). if the reply came within that period then stop the timer and get the reply, if not again check after timer next interval. within 3 interval you not get a reply then better to abort the request and try again by request the same image.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.