Im using QtSDK 4.7.3
I do this in (void test ()):
mgr = new QNetworkAccessManager();
reply = mgr->get(QNetworkRequest(QUrl("http://developer.qt.nokia.com/fileNotExisting.txt")));
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
SLOT(onError(QNetworkReply::NetworkError)), Qt::ConnectionType::UniqueConnection);
And of course, the onError slot is raised:
if (networkError == QNetworkReply::NetworkError::ContentNotFoundError)
{
QMessageBox m;
m.exec();
}
If I don't have the / eventloop message in the onError slot, there is no failure, and everything works. But when it is there, the onError slot is called again when m.exec () is called. When both message boxes are closed and I leave the onError function, the application crashes. The application tries to remove / free memory when this happens. The error "Access to read access violation location" does not help, and the call stack is located deep in the Qt dll.
:
.
test() QApplication exec. ( ).
, HostNotFound, onError .
.
onError, , .
onError().
Qt (post).
- , ?
, :
main.cpp
#include "contentnotfound.h"
#include <QtGui/QApplication>
#include <QTimer>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ContentNotFound cnf;
if (true) { cnf.test(); }
else { QTimer::singleShot(2000, &cnf, SLOT(test())); }
return a.exec();
}
contentnotfound.h
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QMessageBox>
class ContentNotFound : public QObject
{
Q_OBJECT
public slots:
void test()
{
mgr = new QNetworkAccessManager();
reply = mgr->get(QNetworkRequest(QUrl("http://developer.qt.nokia.com/fileNotExisting.txt")));
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
SLOT(onError(QNetworkReply::NetworkError)), Qt::ConnectionType::UniqueConnection);
}
private slots:
void onError(QNetworkReply::NetworkError networkError)
{
if (networkError == QNetworkReply::NetworkError::ContentNotFoundError)
{
QMessageBox m;
m.exec();
}
}
private:
QNetworkAccessManager* mgr;
QNetworkReply* reply;
};