Search code examples
c++qtqnetworkaccessmanager

Does the QNetworkAccessManager destructor abort the current requests?


Working on an application where the user should be able to cancel all the uploads. Now I wonder if I have to hunt down all the replies from the QNAM or just delete it and expect them all to abort then?

There's nothing in the doc stating anything about aborting but I'm assuming that it will.

Destroys the QNetworkAccessManager object and frees up any resources. Note that QNetworkReply objects that are returned from this class have this object set as their parents, which means that they will be deleted along with it if you don't call QObject::setParent() on them.

EDIT: Ended up using a wrapper for every reply (which also takes ownership over it and does retrys etc) which in its destructor both disconnects the QNetworkReplys signals aswell as abort it. The it gets deleted along with the wrapper (parent->child)


Solution

  • It will just delete the replies. From the source:

    QNetworkAccessManager::~QNetworkAccessManager()
    {
        // ...
    
        qDeleteAll(findChildren<QNetworkReply *>());
    
        // ...
    }
    

    And the destructor of QNetworkReply is empty, so you need to abort them manually.