Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QNetworkAccessManager::get spawns 3 threads and I cannot close them

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

Scheduled Pinned Locked Moved General and Desktop
10 Posts 2 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gsmember
    wrote on last edited by
    #1

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

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

    private:
    QNetworkAccessManager *manager;
    QNetworkReply *reply;
    QUrl url;

    public slots:
    void slot_requestFinished();
    @

    request.cpp:
    @
    #include "request.h"

    Request::Request(){
    manager=new QNetworkAccessManager(this);
    reply=0;
    }

    Request::~Request(){
    if(manager!=0){
    manager->deleteLater();
    }
    if(reply!=0){
    reply->deleteLater();
    }
    }

    void Request::func_startRequest(){
    QNetworkRequest request;
    request.setUrl(QUrl("http://qt-project.org/"));

    reply=manager->get(request);
    
    connect(reply, SIGNAL(finished()), this, SLOT(slot_requestFinished()));
    

    }

    void Request::slot_requestFinished(){
    disconnect(reply,SIGNAL(finished()),this,SLOT(slot_requestFinished()));

    /*QNetworkSession session(manager->configuration());
    session.close();
    session.stop();
    reply->abort();
    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

    _gs

    1 Reply Last reply
    0
    • G Offline
      G Offline
      gsmember
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • G Offline
          G Offline
          gsmember
          wrote on last edited by
          #4

          Hello,
          thanks for your reply.

          Sorry I forgot to mention the specs:

          • Qt 4.8.4 on Debian 5
          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

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

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • G Offline
              G Offline
              gsmember
              wrote on last edited by
              #6

              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().

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Did you already check if something was reported on the "bug report system":http://bugreports.qt-project.org/issues ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  gsmember
                  wrote on last edited by
                  #8

                  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.

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

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    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)

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      gsmember
                      wrote on last edited by
                      #10

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

                      _gs

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved