QNetworkAccessManager contineous fetching data crashes app
-
hi,
I am developing app has to fetch data from sever continuously n print on screen , this app is running fine but after some time (aprox 30 min) shows memory full error and exits...please someone help me resolve it ....
even i am setting don't save cache n even cookies...please help me...
my code to fetch data is as follows..
@
void mainWindow::Connection(QString url, QString data)
{
QNetworkRequest request=new QNetworkRequest(QUrl(URL));
request->setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded");
QNetworkAccessManager net = new QNetworkAccessManager;
QNetworkAccessManager::connect(net, SIGNAL(finished(QNetworkReply)),
this ,SLOT(replyFinished(QNetworkReply)));
request->setAttribute(QNetworkRequest::CacheSaveControlAttribute,false);
request->setAttribute(QNetworkRequest::CookieSaveControlAttribute,false);QByteArray data;
QUrl params1;net->post(*request,data);
}
void mainWindow::replyFinished(QNetworkReply *reply)
{
if(reply->error()==QNetworkReply::NoError)
{
QString data=reply->readAll();
qDebug()<<reply->url().toString();} else { qDebug()<<reply->errorString(); Error *msg=new Error("no Internet connection."); msg->show(); } reply->deleteLater();
}
// again call to connection fn after delay of 15 sec
}
@and my reply fn is as below
-
What about such code, which will use one QNAM and connect to finished signal of reply.
@
void mainWindow::Connection(QString url, QString data1)
{
QNetworkRequest *request=new QNetworkRequest(QUrl(URL));
request->setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded");
request->setAttribute(QNetworkRequest::CacheSaveControlAttribute,false);
request->setAttribute(QNetworkRequest::CookieSaveControlAttribute,false);
QByteArray data;
QNetworkReply * reply = manager->post(*request,data);connect(reply, SIGNAL(finished()), this ,SLOT(replyFinished()));
}
@By the way, you have two variables which the same name
@
QString data //in function parameters
QByteArray data //within body of function@