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:
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
-
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.
-
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
-
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().
-
Did you already check if something was reported on the "bug report system":http://bugreports.qt-project.org/issues ?
-
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.
-
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.
_gs