Important: Please read the Qt Code of Conduct -

QNetworkAccessManager::get spawns 3 threads and I cannot close them

  • Hello guys,
    I am really getting headache with this problem.

    I will show you the affected piece of code:
    @class Request: public QObject{
    void func_startRequest();

    QNetworkAccessManager *manager;
    QNetworkReply *reply;
    QUrl url;

    public slots:
    void slot_requestFinished();

    #include "request.h"

    manager=new QNetworkAccessManager(this);


    void Request::func_startRequest(){
    QNetworkRequest request;

    connect(reply, SIGNAL(finished()), this, SLOT(slot_requestFinished()));


    void Request::slot_requestFinished(){

    /*QNetworkSession session(manager->configuration());
    reply->close(); I have tried all of this methods, nothing shut down the threads */


    My problem is that, whenever I call manager->get(), this spawns 3 threads, which I am unable to shut down. After a while (running many requests) there were a huge amount of running threads. They are consuming RAM and running out of max open file descriptors...

    Maybe someone could help me with this problem. I would really appreciate that!

    Thanks guys


  • I am talking about threads, not processess. After the first request there were four running thread, the main thread plus 3 threads started by QNAM.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    This sounds like a rather strange behavior. What version of Qt are you using on which platform ?

  • Hello,
    thanks for your reply.

    Sorry I forgot to mention the specs:

    • Qt 4.8.4 on Debian 5

  • Lifetime Qt Champion

    Just to be sure, aren't you forgetting to delete the reply ?

  • Yes, I have also tried to delete the manager and the reply (with deleteLater() ) right after the finished() signal was thrown. Deleting the manger caused the running process amount (opened by QNAM) to reduce to 2 (instead of 3).

    And I am very confident that the problem relies on the QNAM, because the three processess (shown in htop and ptree) are spawned right after I call manager->get().

  • Lifetime Qt Champion

    Did you already check if something was reported on the "bug report system": ?

  • Yes, I have found the following closed bugreport, which seems to be very similar to my problem. Indeed, I am hitting the open file limit, but I as penny said, QNAM does not provide any method (or any known one) to close the processess.

  • Lifetime Qt Champion

    You're not really in the same use case. You could try asking on the interest mailing list to see whether this is an intended behavior. You'll find Qt's developers/maintainers there (this forum is more user oriented)

  • Okay I will do so. Thank you for your interests.


Log in to reply