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



  • How do you delete objects, for instance QNetworkReply?



  • i am using " reply->deleteLater(); "



  • Do you have to create a new QNAM for each request? Could you use one manager?



  • i have all diff request like i have 4 to 5 different Urls and even i am having some other requests except this timer request on particular button press ,so i implemented like this ... i don't know i can use or not...



  • 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

    @



  • i have just given sample ... i can't post complete code so...

    ok i will try..


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.