QT QNetworkAccessManager内存泄漏
有一个纠结的问题,现做一个HTTP客户端,使用QNetworkAccessManager发现有内存泄漏现象,特意写了一个测试代码,如下:
nettest.h
#ifndef NETTEST_H#define NETTEST_H#include <QtGui/QWidget>#include "ui_nettest.h"#include <QNetworkAccessManager>#include <QNetworkRequest>#include <QNetworkReply>class NetTest : public QWidget{ Q_OBJECTpublic: NetTest(QWidget *parent = 0); ~NetTest();private: Ui::NetTestClass ui; QNetworkAccessManager *qnam; QNetworkRequest qnr;public slots: void onSend(); void accept(QNetworkReply *r);};#endif // NETTEST_H
#include "nettest.h"#include <QDebug>NetTest::NetTest(QWidget *parent) : QWidget(parent){ ui.setupUi(this); connect(ui.pushButton,SIGNAL(clicked()),this,SLOT(onSend())); qnr.setUrl(QUrl("http://www.baidu.com/")); qnam=new QNetworkAccessManager(); connect(qnam, SIGNAL(finished(QNetworkReply *)), this,SLOT(accept(QNetworkReply *)));}void NetTest::onSend(){ qDebug()<<"发送数据!"; qnam->get(qnr);}void NetTest::accept(QNetworkReply *r){ qDebug()<<"接收数据!"; qDebug()<<r->readAll();}