Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QNetworkAccessManager contineous fetching data crashes app
Forum Update on Monday, May 27th 2025

QNetworkAccessManager contineous fetching data crashes app

Scheduled Pinned Locked Moved Mobile and Embedded
7 Posts 2 Posters 2.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    spsp
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • G Offline
      G Offline
      guziemic
      wrote on last edited by
      #2

      How do you delete objects, for instance QNetworkReply?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        spsp
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • G Offline
          G Offline
          guziemic
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • S Offline
            S Offline
            spsp
            wrote on last edited by
            #5

            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...

            1 Reply Last reply
            0
            • G Offline
              G Offline
              guziemic
              wrote on last edited by
              #6

              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

              @

              1 Reply Last reply
              0
              • S Offline
                S Offline
                spsp
                wrote on last edited by
                #7

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

                ok i will try..

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved