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. QNetworkAccessManger is not ok for mem
Qt 6.11 is out! See what's new in the release blog

QNetworkAccessManger is not ok for mem

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
3 Posts 2 Posters 433 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.
  • T Offline
    T Offline
    test_song
    wrote on last edited by
    #1

    Que: my Code is this,QT Ver is QT5.9.4

    ohh,My program encountered a problem。
    in slots function replyFinished . reply-deleter() is called before return. but the mem continues to increase。
    I expect for your reply 。thanks.

        QNetworkReply *replay=http->post(req, d);
        connect(replay,SIGNAL(finished(QNetworkReply*)),this,SLOT(replyFinished(QNetworkReply*)));
        replyTimeout *reply_timer=new replyTimeout(replay,5000);
    
    
    
    void httpRequest::replyFinished(QNetworkReply *reply)
    {
        QString r_url;
        r_url=reply->url().toString();
        QByteArray r_byte;
        r_byte.clear();
    
        if(reply->error() != QNetworkReply::NoError)
        {
    
            r_byte=reply->errorString().toUtf8();
            send_notify_err(r_url,1);
            qDebug("QNetworkReply::err  %d",reply->error());
            reply->deleteLater();
            return ;
        }
        r_byte= reply->readAll();
        if (r_byte.isEmpty())
        {
            r_byte=QString("isEmpty").toUtf8();
    
            send_notify_err(r_url,2);
    
            reply->deleteLater();
    
            qDebug()<<"r_content isEmpty()";
    
            return ;
        }
    
       // m_callbackFunc(&r_url,&r_byte);
        reply->deleteLater();
        send_notify_msg(r_url,r_byte);
    
    }
    
    jsulmJ 1 Reply Last reply
    0
    • T test_song

      Que: my Code is this,QT Ver is QT5.9.4

      ohh,My program encountered a problem。
      in slots function replyFinished . reply-deleter() is called before return. but the mem continues to increase。
      I expect for your reply 。thanks.

          QNetworkReply *replay=http->post(req, d);
          connect(replay,SIGNAL(finished(QNetworkReply*)),this,SLOT(replyFinished(QNetworkReply*)));
          replyTimeout *reply_timer=new replyTimeout(replay,5000);
      
      
      
      void httpRequest::replyFinished(QNetworkReply *reply)
      {
          QString r_url;
          r_url=reply->url().toString();
          QByteArray r_byte;
          r_byte.clear();
      
          if(reply->error() != QNetworkReply::NoError)
          {
      
              r_byte=reply->errorString().toUtf8();
              send_notify_err(r_url,1);
              qDebug("QNetworkReply::err  %d",reply->error());
              reply->deleteLater();
              return ;
          }
          r_byte= reply->readAll();
          if (r_byte.isEmpty())
          {
              r_byte=QString("isEmpty").toUtf8();
      
              send_notify_err(r_url,2);
      
              reply->deleteLater();
      
              qDebug()<<"r_content isEmpty()";
      
              return ;
          }
      
         // m_callbackFunc(&r_url,&r_byte);
          reply->deleteLater();
          send_notify_msg(r_url,r_byte);
      
      }
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @test_song said in QNetworkAccessManger is not ok for mem:

      replyTimeout *reply_timer=new replyTimeout(replay,5000);

      What do you use this for? In the code you posted you do not delete it.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • T Offline
        T Offline
        test_song
        wrote on last edited by
        #3

        @test_song said in QNetworkAccessManger is not ok for mem:

        reply_timer

        this reply_timer is a class to monitor ,reply is it's father, it deleted with reply erased
        class replyTimeout : public QObject {

        Q_OBJECT
        

        public:
        replyTimeout(QNetworkReply *reply, const int timeout) : QObject(reply) {
        Q_ASSERT(reply);
        if (reply && reply->isRunning()) { // 启动单次定时器
        QTimer::singleShot(timeout, this, SLOT(onTimeout()));
        }
        }
        ~replyTimeout()
        {
        qDebug()<<"~replyTimeout";
        }
        private slots:
        void onTimeout() { // 处理超时
        QNetworkReply reply = static_cast<QNetworkReply>(parent());
        if (reply->isRunning()) {
        qDebug() << "abort reply "<< reply->url().toString();
        reply->abort();
        }
        }
        };

        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