Search code examples
qtftpqnetworkaccessmanager

Method to reset the QNetworkAccessManager backend


It seems that QNetworkAccessManager does not handle missing files retrieved by ftp if the ftp server requires authentication.

The situation is this: I'm downloading multiple files from the same ftp server that requires username and password. I successfully download a few files then send a GET for a file that does not exist. That request reports failure. I then send a GET request for a file that should be valid. That request never emits a finished signal or error.

Qt 4.7.4

Please help! This is driving me nuts. I think that if I can somehow reset the ftp backend, this problem might be solvable.


Solution

  • You are connecting the QNetworkReply signal finished() like this:

    QObject::connect(reply, SIGNAL(finished()), netty, SLOT(finished()));
    

    Instead try the finished signal from the QNetworkAccessManager like this:

    connect(&network, SIGNAL(finished(QNetworkReply *)), netty, SLOT(finished(QNetworkReply *)));
    

    Note that you will have to change the prototype for your finished() slot.

    A final method would be to set a timer that calls a function like this:

    void check(QNetworkReply *reply){
     if(reply != NULL){
       if(reply->isFinished())
         finished(reply);
       else
         reply->abort();
     }
    }
    

    And be aware of this bug:

    https://bugreports.qt-project.org/browse/QTBUG-3443