Different back trace but have the same result, 
For test this case, I create a new Visual Studio project, and my test code list below. May be someone can test this code
//test.h
#ifndef TEST_H
#define TEST_H
#include <QtWidgets/QMainWindow>
#include <QtNetwork>
#include "ui_test.h"
{
Q_OBJECT
public:
~Test();
public slots:
void Button_clicked();
void destroy_clicked();
void Request_finished(QNetworkReply *reply);
private:
Ui::TestClass ui;
QNetworkReply* reply;
QNetworkAccessManager* manager;
};
#endif // TEST_H
//test.h
#ifndef TEST_H
#define TEST_H
#include <QtWidgets/QMainWindow>
#include <QtNetwork>
#include "ui_test.h"
class Test : public QMainWindow
{
Q_OBJECT
public:
Test(QWidget *parent = 0);
~Test();
public slots:
void Button_clicked();
void destroy_clicked();
void Request_finished(QNetworkReply *reply);
private:
Ui::TestClass ui;
QNetworkReply* reply;
QNetworkAccessManager* manager;
};
#endif // TEST_H
To copy to clipboard, switch view to plain text mode
//test.cpp
#include "test.h"
#include <QtWidgets>
{
ui.setupUi(this);
QObject::connect(ui.
pushButton,
SIGNAL(clicked
()),
this,
SLOT(Button_clicked
()));
QObject::connect(ui.
btn_destroy,
SIGNAL(clicked
()),
this,
SLOT(destroy_clicked
()));
reply = NULL;
manager = NULL;
}
Test::~Test()
{
}
void Test::Request_finished(QNetworkReply *reply)
{
//reply->deleteLater();
}
void Test::Button_clicked()
{
manager = new QNetworkAccessManager(this);
QObject::connect(manager,
SIGNAL(finished
(QNetworkReply
*)),
this,
SLOT(Request_finished
(QNetworkReply
*)));
QNetworkRequest request
(QUrl("http://www.google.com"));
reply = manager->get(request);
}
void Test::destroy_clicked()
{
qDebug() << "to delete reply...";
if (reply)
{
reply->abort();
delete reply;//->deleteLater();
reply = NULL;
}
qDebug() << "to delete manager...";
if (manager)
{
delete manager;
manager = NULL;
}
qDebug() << "reply, manager destroyed...";
}
//test.cpp
#include "test.h"
#include <QtWidgets>
Test::Test(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
QObject::connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(Button_clicked()));
QObject::connect(ui.btn_destroy, SIGNAL(clicked()), this, SLOT(destroy_clicked()));
reply = NULL;
manager = NULL;
}
Test::~Test()
{
}
void Test::Request_finished(QNetworkReply *reply)
{
//reply->deleteLater();
}
void Test::Button_clicked()
{
manager = new QNetworkAccessManager(this);
QObject::connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(Request_finished(QNetworkReply *)));
QNetworkRequest request(QUrl("http://www.google.com"));
reply = manager->get(request);
}
void Test::destroy_clicked()
{
qDebug() << "to delete reply...";
if (reply)
{
reply->abort();
delete reply;//->deleteLater();
reply = NULL;
}
qDebug() << "to delete manager...";
if (manager)
{
delete manager;
manager = NULL;
}
qDebug() << "reply, manager destroyed...";
}
To copy to clipboard, switch view to plain text mode
Bookmarks