c++ - Why does my application crash on exit after invoked QNetowrkAccessManager::get? -
i using qt 5.7 32bit in visual studio 2015. want http qnetworkaccessmanager. but, application crashed when closing application. because, when calling qnetworkmanager::get function , closing window, access violation exception occurs in qnetwork.dll , application abort . (if comment out line calling qnetworkmanager::get function, abnormal termination doesn't occur.) specifically, call stack follows. happened in qnetwork.dll , others.
ntdll.dll!7770904e() unknown [frames below may incorrect and/or missing, no symbols loaded ntdll.dll] [external code] libeay32.dll!020b122e() unknown libeay32.dll!02120e0c() unknown libeay32.dll!02117592() unknown libeay32.dll!021176cb() unknown libeay32.dll!0211764c() unknown libeay32.dll!021177e0() unknown libeay32.dll!021174e0() unknown libeay32.dll!02113d7e() unknown qt5networkd.dll!q_x509_free(x509_st * a) line 354 c++ qt5networkd.dll!qsslcertificateprivate::~qsslcertificateprivate() line 92 c++ [external code] qt5networkd.dll!qexplicitlyshareddatapointer<qsslcertificateprivate>::~qexplicitlyshareddatapointer<qsslcertificateprivate>() line 165 c++ qt5networkd.dll!qsslcertificate::~qsslcertificate() line 175 c++ [external code] qt5networkd.dll!qlist<qsslcertificate>::node_destruct(qlist<qsslcertificate>::node * from, qlist<qsslcertificate>::node * to) line 492 c++ qt5networkd.dll!qlist<qsslcertificate>::dealloc(qlistdata::data * data) line 863 c++ qt5networkd.dll!qlist<qsslcertificate>::~qlist<qsslcertificate>() line 824 c++ [external code] qt5networkd.dll!qexplicitlyshareddatapointer<qsslconfigurationprivate>::~qexplicitlyshareddatapointer<qsslconfigurationprivate>() line 165 c++ [external code]
the main parts of source code shown below. htmldocument class contains html document , uri omit source codes.
mainwindow.hpp
#ifndef mainwindow_hpp #define mainwindow_hpp #include <qmainwindow> #include <qwidget> #include <qnetworkaccessmanager> #include <qgraphicsscene> #include <qgraphicsitem> #include "testquery.hpp" #include "htmldocument.hpp" class mainwindow : public qmainwindow { q_object public: mainwindow(qwidget *parent = 0); public slots: void onreceived(htmldocument const& doc); private: testquery* query; }; #endif // mainwindow_hpp
mainwindow.cpp
#include "mainwindow.hpp" #include <qfile> mainwindow::mainwindow(qwidget *parent) : qmainwindow(parent) { this->query = new testquery(this); this->query->seturi("any url http request.").query(); this->connect(this->query, signal(queryfinished(htmldocument)), this, slot(onreceived(htmldocument))); } void mainwindow::onreceived(const htmldocument& doc) { qdebug() << "[received]:html document"; qfile file("output.html"); file.open(qfile::openmodeflag::truncate | qfile::openmodeflag::writeonly); auto binary = doc.document().tolocal8bit(); file.write(binary); file.flush(); file.close(); }
testquery.hpp
#ifndef testquery_hpp #define testquery_hpp #include <qnetworkaccessmanager> #include <qnetworkreply> #include <qnetworkaccessmanager> #include <qurl> #include "htmldocument.hpp" class testquery : public qobject { q_object public: explicit testquery(qobject* parent = nullptr); void query(); testquery& seturi(qstring const& uri); public slots: void onreply(qnetworkreply* reply); signals: void queryfinished(htmldocument); private: void generateuriquery(qurl& uri, qurlquery& query); htmldocument generatehtmldocument(qbytearray const& data); private: qnetworkaccessmanager* manager_; qurl uri_; }; #endif // !testquery_hpp
testquery.cpp
#include "testquery.hpp" #include <qnetworkreply> #include <qfile> #include <qurl> #include <qurlquery> testquery::testquery(qobject* parent) : qobject(parent) { this->manager_ = new qnetworkaccessmanager(this); } void testquery::query() { qurl uri; qurlquery query; this->generateuriquery(uri, query); qdebug() << "[url]:" << uri.tostring(); qdebug() << "[query]:" << query.tostring(); qnetworkrequest request(qurl(uri.tostring() + query.tostring(qurl::fullyencoded))); auto result = this->manager_->get(request); this->connect(this->manager_, &qnetworkaccessmanager::finished, this, &testquery::onreply); } testquery & testquery::seturi(qstring const & uri) { this->uri_ = uri; return *this; } void testquery::onreply(qnetworkreply* reply) { qdebug() << "[reply]:come respond."; if (reply->error()) { qdebug() << tr("[error]:") << reply->errorstring(); } else { emit this->queryfinished(this->generatehtmldocument(reply->readall())); } reply->deletelater(); } void testquery::generateuriquery(qurl& uri, qurlquery& query) { uri = this->uri_; } htmldocument testquery::generatehtmldocument(const qbytearray& data) { return htmldocument(qstring::fromlocal8bit(data), this->uri_); }
Comments
Post a Comment