Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Real confusion about when to delete QNetworkReply object
QtWS25 Last Chance

Real confusion about when to delete QNetworkReply object

Scheduled Pinned Locked Moved Solved General and Desktop
31 Posts 7 Posters 2.6k 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.
  • H Offline
    H Offline
    hbatalha
    wrote on last edited by hbatalha
    #1

    I have a class FileDownloader that I have an instance of it in my main class and I use it to download some files by calling a method 'download'. But I am having a hard time understanding when to call deleteLater on the QNetworkReply object.
    Here is the part of the code that I consider relevant. if something is unclear I can post some code or even the entire class:

    void FileDownloader::download(QString url, QString dest_file, QString downloadName, FileDownloadRequestType fileDownloadRequestType)
    {
        this->show();
    
        connect(ui->pushButton, &QPushButton::clicked, [this] { this->close(); });
    
        ui->download_progressBar->setMinimum(0);
        ui->download_progressBar->setMaximum(0);
    
        ui->msg_label->setText(tr("Downloading ") + downloadName);
    
        reply = net.get(QNetworkRequest(QUrl(url)));
    
        downloadBegan = true;
        finished = false;
       
        if(QFile::exists(dest_file))
            QFile::remove(dest_file);
    
        QObject::connect(reply, &QNetworkReply::downloadProgress, [this](qint64 received, qint64 total)
        {
            qDebug() << received << " of " << total;
    
            ui->progress_label->setText(Util::displaySize(received) + " of " + Util::displaySize(total));
    
            ui->download_progressBar->setRange(0, total);
            ui->download_progressBar->setValue(received);
        });
    
        QObject::connect(&net, &QNetworkAccessManager::finished, [this, dest_file, fileDownloadRequestType](QNetworkReply* reply)
        {
            if(! reply->error())
            {
                QByteArray data = reply->readAll();
    
                QFile file(dest_file);           
    
                if( ! file.open(QIODevice::ReadWrite | QIODevice::Truncate))
                    Util::displayErrorMessage(tr("Something went wrong"), tr("Could not save the file"), this, true); // closes the dialog
    
                file.write(data);
                file.close();
    
                ui->msg_label->setText("Download Complete");
                ui->progress_label->setText("");
    
                finished = true;
    
                exe = dest_file;
    
                if(fileDownloadRequestType == FileDownloadRequestType::UPDATE)
                    handleUpdateDownloadFinished();
            }
    
            // reply->deleteLater();  // if I call it here instead it crashes my app every once in a while
        });
    }
    
    void FileDownloader::handleUpdateDownloadFinished()
    {
        ui->download_progressBar->setMinimum(0);
        ui->download_progressBar->setMaximum(0);
        ui->pushButton->setText(tr("Install Update"));
    
        disconnect(ui->pushButton, &QPushButton::clicked, nullptr, nullptr);
        connect(ui->pushButton, &QPushButton::clicked, this, &FileDownloader::install);
    }
    
    void FileDownloader::install()
    {
        QProcess::startDetached(exe);
        qApp->quit();
    }
    
    void FileDownloader::closeEvent(QCloseEvent *)
    {
        if(reply != nullptr && downloadBegan && ! reply->isFinished())
        {
            reply->abort();
        }
    
        reply->deleteLater();
    }
    

    Right now I calling reply->deleteLater(); in the closeEvent( I am really not sure if it is safe) which seems to be working fine. Before I was I calling it in the lambda function connected to the QNetworkAccessManager::finished signal but that was causing my app to crash often.

    I have read through many forums and topics about this and found different approaches. The most common one I found was calling the reply->deleteLater(); in a slot connected to QNetworkAccessManager::finished signal like this:

    void FileDownloader::finished(QNetworkReply* reply)
     {
        QByteArray = reply->readAll();
        reply->deleteLater();
        //do other stuff
    }
    

    Unless I am misunderstanding the doc, it says not to delete the object there.

    Note: Do not delete the object in the slot connected to the errorOccurred() or finished() signal. Use deleteLater().

    In some they use a QScopedPointer to store the reply .

    So I am not sure which is the correct way of deleting the reply.

    jsulmJ 1 Reply Last reply
    0
    • H hbatalha

      I have a class FileDownloader that I have an instance of it in my main class and I use it to download some files by calling a method 'download'. But I am having a hard time understanding when to call deleteLater on the QNetworkReply object.
      Here is the part of the code that I consider relevant. if something is unclear I can post some code or even the entire class:

      void FileDownloader::download(QString url, QString dest_file, QString downloadName, FileDownloadRequestType fileDownloadRequestType)
      {
          this->show();
      
          connect(ui->pushButton, &QPushButton::clicked, [this] { this->close(); });
      
          ui->download_progressBar->setMinimum(0);
          ui->download_progressBar->setMaximum(0);
      
          ui->msg_label->setText(tr("Downloading ") + downloadName);
      
          reply = net.get(QNetworkRequest(QUrl(url)));
      
          downloadBegan = true;
          finished = false;
         
          if(QFile::exists(dest_file))
              QFile::remove(dest_file);
      
          QObject::connect(reply, &QNetworkReply::downloadProgress, [this](qint64 received, qint64 total)
          {
              qDebug() << received << " of " << total;
      
              ui->progress_label->setText(Util::displaySize(received) + " of " + Util::displaySize(total));
      
              ui->download_progressBar->setRange(0, total);
              ui->download_progressBar->setValue(received);
          });
      
          QObject::connect(&net, &QNetworkAccessManager::finished, [this, dest_file, fileDownloadRequestType](QNetworkReply* reply)
          {
              if(! reply->error())
              {
                  QByteArray data = reply->readAll();
      
                  QFile file(dest_file);           
      
                  if( ! file.open(QIODevice::ReadWrite | QIODevice::Truncate))
                      Util::displayErrorMessage(tr("Something went wrong"), tr("Could not save the file"), this, true); // closes the dialog
      
                  file.write(data);
                  file.close();
      
                  ui->msg_label->setText("Download Complete");
                  ui->progress_label->setText("");
      
                  finished = true;
      
                  exe = dest_file;
      
                  if(fileDownloadRequestType == FileDownloadRequestType::UPDATE)
                      handleUpdateDownloadFinished();
              }
      
              // reply->deleteLater();  // if I call it here instead it crashes my app every once in a while
          });
      }
      
      void FileDownloader::handleUpdateDownloadFinished()
      {
          ui->download_progressBar->setMinimum(0);
          ui->download_progressBar->setMaximum(0);
          ui->pushButton->setText(tr("Install Update"));
      
          disconnect(ui->pushButton, &QPushButton::clicked, nullptr, nullptr);
          connect(ui->pushButton, &QPushButton::clicked, this, &FileDownloader::install);
      }
      
      void FileDownloader::install()
      {
          QProcess::startDetached(exe);
          qApp->quit();
      }
      
      void FileDownloader::closeEvent(QCloseEvent *)
      {
          if(reply != nullptr && downloadBegan && ! reply->isFinished())
          {
              reply->abort();
          }
      
          reply->deleteLater();
      }
      

      Right now I calling reply->deleteLater(); in the closeEvent( I am really not sure if it is safe) which seems to be working fine. Before I was I calling it in the lambda function connected to the QNetworkAccessManager::finished signal but that was causing my app to crash often.

      I have read through many forums and topics about this and found different approaches. The most common one I found was calling the reply->deleteLater(); in a slot connected to QNetworkAccessManager::finished signal like this:

      void FileDownloader::finished(QNetworkReply* reply)
       {
          QByteArray = reply->readAll();
          reply->deleteLater();
          //do other stuff
      }
      

      Unless I am misunderstanding the doc, it says not to delete the object there.

      Note: Do not delete the object in the slot connected to the errorOccurred() or finished() signal. Use deleteLater().

      In some they use a QScopedPointer to store the reply .

      So I am not sure which is the correct way of deleting the reply.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @hbatalha said in Real confusion about when to delete QNetworkReply object:

      Use deleteLater()

      And this is exactly what you are doing, right? So, what is the problem?

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

      SGaistS 1 Reply Last reply
      0
      • jsulmJ jsulm

        @hbatalha said in Real confusion about when to delete QNetworkReply object:

        Use deleteLater()

        And this is exactly what you are doing, right? So, what is the problem?

        SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        @jsulm the OP calls deleteLater at the wrong time and also keeps a local copy of the reply which is not needed and on which he might call deleteLater while the pointer is dangling.

        @hbatalha you should call deleteLater in your reply once the request is finished so in your case in the lambda that is connected to the QNAM finished signal.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        jsulmJ H 2 Replies Last reply
        1
        • SGaistS SGaist

          Hi,

          @jsulm the OP calls deleteLater at the wrong time and also keeps a local copy of the reply which is not needed and on which he might call deleteLater while the pointer is dangling.

          @hbatalha you should call deleteLater in your reply once the request is finished so in your case in the lambda that is connected to the QNAM finished signal.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @SGaist Ah, I was looking at

          void FileDownloader::finished(QNetworkReply* reply)
           {
              QByteArray = reply->readAll();
              reply->deleteLater();
              //do other stuff
          }
          

          which is not the actual code.

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

          H 1 Reply Last reply
          0
          • jsulmJ jsulm

            @SGaist Ah, I was looking at

            void FileDownloader::finished(QNetworkReply* reply)
             {
                QByteArray = reply->readAll();
                reply->deleteLater();
                //do other stuff
            }
            

            which is not the actual code.

            H Offline
            H Offline
            hbatalha
            wrote on last edited by
            #5

            @jsulm said in Real confusion about when to delete QNetworkReply object:

            which is not the actual code.

            That was an example I created to show the most commom way I found being suggested to do in other forums

            1 Reply Last reply
            0
            • SGaistS SGaist

              Hi,

              @jsulm the OP calls deleteLater at the wrong time and also keeps a local copy of the reply which is not needed and on which he might call deleteLater while the pointer is dangling.

              @hbatalha you should call deleteLater in your reply once the request is finished so in your case in the lambda that is connected to the QNAM finished signal.

              H Offline
              H Offline
              hbatalha
              wrote on last edited by
              #6

              @SGaist

              you should call deleteLater in your reply once the request is finished

              If I do that the app will ocasionally crash

              the OP calls deleteLater at the wrong time and also keeps a local copy

              In my code where should I call it then?

              on which he might call deleteLater while the pointer is dangling.

              After a download is complete the next time will always be close the dialog so I think there won't be a case where that pointer is dangling unless I am missing something.
              But for for safety I could add condition to see it reply is null or not before calling deleteLater

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                What stack trace do you get when it crashes ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                H 1 Reply Last reply
                0
                • SGaistS SGaist

                  What stack trace do you get when it crashes ?

                  H Offline
                  H Offline
                  hbatalha
                  wrote on last edited by
                  #8

                  @SGaist I get this
                  Screenshot_1.png

                  Which points to this line in the closeEvent ;

                   if(reply != nullptr && downloadBegan && ! reply->isFinished())
                  

                  This is the connect slot used:

                  QObject::connect(&net, &QNetworkAccessManager::finished, [this, dest_file, fileDownloadRequestType](QNetworkReply* reply)
                      {
                          if(! reply->error())
                          {
                              QByteArray data = reply->readAll();
                              reply->deleteLater();
                  
                              QFile file(dest_file);
                  
                              if( ! file.open(QIODevice::ReadWrite | QIODevice::Truncate))
                                  Util::displayErrorMessage(tr("Something went wrong"), tr("Could not save the file"), this, true);
                  
                              file.write(data);
                              file.close();
                  
                              ui->msg_label->setText(tr("Download Complete"));
                              ui->progress_label->setText("");
                  
                              finished = true;
                  
                              exe = dest_file;
                  
                              if(fileDownloadRequestType == FileDownloadRequestType::UPDATE)
                                  handleUpdateDownloadFinished();
                          }
                      });
                  

                  The difference here I call deleteLater right after QByteArray data = reply->readAll();

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    You know that deleteLater does not change that pointer to a nullptr value ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    H 1 Reply Last reply
                    1
                    • JoeCFDJ Offline
                      JoeCFDJ Offline
                      JoeCFD
                      wrote on last edited by JoeCFD
                      #10

                      Use this to check if reply finishes before it is deleted.
                      connect( m_reply, &QNetworkReply::finished, **** );

                      Normally, you may do the following because it may finish immediately and the slot may not be called. Sigh!

                         if ( nullptr != m_reply ) { /* check reply is null or not first */
                             if ( m_reply->isRunning() ) { /* connect when it is still running */
                                 connect( m_reply, &QNetworkReply::finished,
                                          this,    &getFinished() );
                             }
                             else { /* not running(already finished) and call slot directly while connection is not needed */
                                 getFinished();
                             }
                         }
                      
                      H jeremy_kJ 2 Replies Last reply
                      0
                      • SGaistS SGaist

                        You know that deleteLater does not change that pointer to a nullptr value ?

                        H Offline
                        H Offline
                        hbatalha
                        wrote on last edited by
                        #11

                        @SGaist said in Real confusion about when to delete QNetworkReply object:

                        You know that deleteLater does not change that pointer to a nullptr value ?

                        Yeah, which is making me confused on why it's crashing the app. Any ideas?

                        I made some changes in these two functions:

                        void FileDownloader::download(QString url, QString dest_file, QString downloadName, FileDownloadRequestType fileDownloadRequestType)
                        {
                            this->show();
                        
                            downloadBegan = false;
                            finished = false;
                        
                            connect(ui->pushButton, &QPushButton::clicked, [this] { this->close(); });
                        
                            if(MAIN.preferences.theme == Preferences::Theme::DARK)
                            {
                                ui->msg_label->setStyleSheet("color : white;");
                                ui->progress_label->setStyleSheet("color : white;");
                            }
                            else  if(MAIN.preferences.theme == Preferences::Theme::LIGHT)
                            {
                                ui->msg_label->setStyleSheet("color : black;");
                                ui->progress_label->setStyleSheet("color : black;");
                            }
                        
                            ui->download_progressBar->setMinimum(0);
                            ui->download_progressBar->setMaximum(0);
                        
                            ui->msg_label->setText(tr("Downloading ") + downloadName);
                        
                            reply = net.get(QNetworkRequest(QUrl(url)));
                        
                            downloadBegan = true;
                            finished = false;
                        
                            if(QFile::exists(dest_file))
                                QFile::remove(dest_file);
                        
                            QObject::connect(reply, &QNetworkReply::downloadProgress, [this](qint64 received, qint64 total)
                            {
                                qDebug() << received << " of " << total;
                        
                                ui->progress_label->setText(Util::displaySize(received) + " of " + Util::displaySize(total));
                        
                                ui->download_progressBar->setRange(0, total);
                                ui->download_progressBar->setValue(received);
                            });
                        
                            QObject::connect(&net, &QNetworkAccessManager::finished, [this, dest_file, fileDownloadRequestType](QNetworkReply* reply)
                            {
                                finished = true;
                        
                                if(! reply->error())
                                {
                                    QByteArray data = reply->readAll();
                                    reply->deleteLater();
                        
                                    QFile file(dest_file);
                        
                                    if( ! file.open(QIODevice::ReadWrite | QIODevice::Truncate))
                                        Util::displayErrorMessage(tr("Something went wrong"), tr("Could not save the file"), this, true);
                        
                                    qDebug() << "Size written: " <<  file.write(data);
                                    file.close();
                        
                                    ui->msg_label->setText(tr("Download Complete"));
                                    ui->progress_label->setText("");
                        
                                    exe = dest_file;
                        
                                    if(fileDownloadRequestType == FileDownloadRequestType::UPDATE)
                                        handleUpdateDownloadFinished();
                                }
                            });
                        }
                        
                        void FileDownloader::closeEvent(QCloseEvent *)
                        {
                            if( downloadBegan && ! finished)
                                reply->abort();
                        }
                        

                        Instead of using the reply object to check if the download has finished I am using bool variables. I call deleteLater in the slot.

                        JKSHJ 1 Reply Last reply
                        0
                        • JoeCFDJ JoeCFD

                          Use this to check if reply finishes before it is deleted.
                          connect( m_reply, &QNetworkReply::finished, **** );

                          Normally, you may do the following because it may finish immediately and the slot may not be called. Sigh!

                             if ( nullptr != m_reply ) { /* check reply is null or not first */
                                 if ( m_reply->isRunning() ) { /* connect when it is still running */
                                     connect( m_reply, &QNetworkReply::finished,
                                              this,    &getFinished() );
                                 }
                                 else { /* not running(already finished) and call slot directly while connection is not needed */
                                     getFinished();
                                 }
                             }
                          
                          H Offline
                          H Offline
                          hbatalha
                          wrote on last edited by
                          #12

                          @JoeCFD I didn't quite understand the code

                          JoeCFDJ 1 Reply Last reply
                          0
                          • H hbatalha

                            @JoeCFD I didn't quite understand the code

                            JoeCFDJ Offline
                            JoeCFDJ Offline
                            JoeCFD
                            wrote on last edited by
                            #13

                            @hbatalha added comments.

                            H 1 Reply Last reply
                            0
                            • fcarneyF Offline
                              fcarneyF Offline
                              fcarney
                              wrote on last edited by fcarney
                              #14

                              We do something like this:

                              connect(reply, &QNetworkReply::finished, someobject, &SomeObject::someHandler); // or lambda
                              connect(reply, &QNetworkReply::finished, reply, &QObject::deleteLater);
                              

                              This keeps the lifetime of the reply separate from the "someobject".

                              C++ is a perfectly valid school of magic.

                              H 1 Reply Last reply
                              0
                              • H hbatalha

                                @SGaist said in Real confusion about when to delete QNetworkReply object:

                                You know that deleteLater does not change that pointer to a nullptr value ?

                                Yeah, which is making me confused on why it's crashing the app. Any ideas?

                                I made some changes in these two functions:

                                void FileDownloader::download(QString url, QString dest_file, QString downloadName, FileDownloadRequestType fileDownloadRequestType)
                                {
                                    this->show();
                                
                                    downloadBegan = false;
                                    finished = false;
                                
                                    connect(ui->pushButton, &QPushButton::clicked, [this] { this->close(); });
                                
                                    if(MAIN.preferences.theme == Preferences::Theme::DARK)
                                    {
                                        ui->msg_label->setStyleSheet("color : white;");
                                        ui->progress_label->setStyleSheet("color : white;");
                                    }
                                    else  if(MAIN.preferences.theme == Preferences::Theme::LIGHT)
                                    {
                                        ui->msg_label->setStyleSheet("color : black;");
                                        ui->progress_label->setStyleSheet("color : black;");
                                    }
                                
                                    ui->download_progressBar->setMinimum(0);
                                    ui->download_progressBar->setMaximum(0);
                                
                                    ui->msg_label->setText(tr("Downloading ") + downloadName);
                                
                                    reply = net.get(QNetworkRequest(QUrl(url)));
                                
                                    downloadBegan = true;
                                    finished = false;
                                
                                    if(QFile::exists(dest_file))
                                        QFile::remove(dest_file);
                                
                                    QObject::connect(reply, &QNetworkReply::downloadProgress, [this](qint64 received, qint64 total)
                                    {
                                        qDebug() << received << " of " << total;
                                
                                        ui->progress_label->setText(Util::displaySize(received) + " of " + Util::displaySize(total));
                                
                                        ui->download_progressBar->setRange(0, total);
                                        ui->download_progressBar->setValue(received);
                                    });
                                
                                    QObject::connect(&net, &QNetworkAccessManager::finished, [this, dest_file, fileDownloadRequestType](QNetworkReply* reply)
                                    {
                                        finished = true;
                                
                                        if(! reply->error())
                                        {
                                            QByteArray data = reply->readAll();
                                            reply->deleteLater();
                                
                                            QFile file(dest_file);
                                
                                            if( ! file.open(QIODevice::ReadWrite | QIODevice::Truncate))
                                                Util::displayErrorMessage(tr("Something went wrong"), tr("Could not save the file"), this, true);
                                
                                            qDebug() << "Size written: " <<  file.write(data);
                                            file.close();
                                
                                            ui->msg_label->setText(tr("Download Complete"));
                                            ui->progress_label->setText("");
                                
                                            exe = dest_file;
                                
                                            if(fileDownloadRequestType == FileDownloadRequestType::UPDATE)
                                                handleUpdateDownloadFinished();
                                        }
                                    });
                                }
                                
                                void FileDownloader::closeEvent(QCloseEvent *)
                                {
                                    if( downloadBegan && ! finished)
                                        reply->abort();
                                }
                                

                                Instead of using the reply object to check if the download has finished I am using bool variables. I call deleteLater in the slot.

                                JKSHJ Offline
                                JKSHJ Offline
                                JKSH
                                Moderators
                                wrote on last edited by
                                #15

                                @hbatalha said in Real confusion about when to delete QNetworkReply object:

                                @SGaist said in Real confusion about when to delete QNetworkReply object:

                                You know that deleteLater does not change that pointer to a nullptr value ?

                                Yeah, which is making me confused on why it's crashing the app. Any ideas?

                                1. Most important: Set FileDownloader::reply to nullptr after you call deleteLater().
                                2. Second most important: Give your member variable a different name. Don't call it reply, since your lamba's parameter is also called reply. This causes shadowing (https://www.learncpp.com/cpp-tutorial/variable-shadowing-name-hiding/ )

                                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                                1 Reply Last reply
                                3
                                • jeremy_kJ Offline
                                  jeremy_kJ Offline
                                  jeremy_k
                                  wrote on last edited by
                                  #16

                                  For Qt 5.14 and later, theres QNetworkAccessmanager::setAutoDeleteReplies() which calls deleteLater() after emitting the finished signal.

                                  Asking a question about code? http://eel.is/iso-c++/testcase/

                                  H 1 Reply Last reply
                                  2
                                  • JoeCFDJ JoeCFD

                                    @hbatalha added comments.

                                    H Offline
                                    H Offline
                                    hbatalha
                                    wrote on last edited by
                                    #17

                                    @JoeCFD Thanks I understand now.
                                    I didn't know that it could finish immediately and the slot may not be called. What would happen if that happens. I am curious.

                                    /* check reply is null or not first */

                                    Why would we do something like that. Is there any chance that the QNetworkAccessManager::get() may return a nullptr?

                                    JoeCFDJ 1 Reply Last reply
                                    0
                                    • fcarneyF fcarney

                                      We do something like this:

                                      connect(reply, &QNetworkReply::finished, someobject, &SomeObject::someHandler); // or lambda
                                      connect(reply, &QNetworkReply::finished, reply, &QObject::deleteLater);
                                      

                                      This keeps the lifetime of the reply separate from the "someobject".

                                      H Offline
                                      H Offline
                                      hbatalha
                                      wrote on last edited by
                                      #18

                                      @fcarney said in Real confusion about when to delete QNetworkReply object:

                                      connect(reply, &QNetworkReply::finished, reply, &QObject::deleteLater);

                                      So this is the same as @jeremy_k answer: QNetworkAccessmanager::setAutoDeleteReplies() ?

                                      1 Reply Last reply
                                      0
                                      • jeremy_kJ jeremy_k

                                        For Qt 5.14 and later, theres QNetworkAccessmanager::setAutoDeleteReplies() which calls deleteLater() after emitting the finished signal.

                                        H Offline
                                        H Offline
                                        hbatalha
                                        wrote on last edited by
                                        #19

                                        @jeremy_k So that will eradicate the need to call deleteLater?

                                        JKSHJ 1 Reply Last reply
                                        0
                                        • H hbatalha

                                          @jeremy_k So that will eradicate the need to call deleteLater?

                                          JKSHJ Offline
                                          JKSHJ Offline
                                          JKSH
                                          Moderators
                                          wrote on last edited by JKSH
                                          #20

                                          @hbatalha said in Real confusion about when to delete QNetworkReply object:

                                          So that will eradicate the need to call deleteLater?

                                          Yes, that means you don't need to call deleteLater() yourself. But you must still set your pointer to nullptr.

                                          OR, avoid storing the QNetworkReply as a member variable.

                                          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                                          H 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