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. Correct way to delete QNetworkRequest?

Correct way to delete QNetworkRequest?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 688 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
    Taytoo
    wrote on last edited by
    #1

    I'm creating a QNetworkRequest on heap and then in QNetworkAccessManager::finished signal when I try to delete it, an exception is thrown. Unlike QNetworkReply there is no deleteLater method that I can use either?

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

      No it does not.

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

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

        Hi,

        Don't create your request on the heap, there's no need for that.

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

        T 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

          Don't create your request on the heap, there's no need for that.

          T Offline
          T Offline
          Taytoo
          wrote on last edited by Taytoo
          #3

          @SGaist Basically I've created a custom struct to track each REST request. The custom struct (not QObject) contains associated QNetworkRequest and QNetworkReply pointers.

          The issue is that I also delete REST request struct in QNetworkAccessManager::finished signal, so even if I create QNetworkRequest on stack inside my custom struct, my custom struct is created on heap and deleted inside the finished signal, so wouldn't that result in same error?

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

            Why do you need to keep the request object ?

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

            T 1 Reply Last reply
            0
            • SGaistS SGaist

              Why do you need to keep the request object ?

              T Offline
              T Offline
              Taytoo
              wrote on last edited by
              #5

              @SGaist I assumed it needs to be kept until the request is processed?

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

                No it does not.

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

                T 1 Reply Last reply
                2
                • SGaistS SGaist

                  No it does not.

                  T Offline
                  T Offline
                  Taytoo
                  wrote on last edited by
                  #7

                  @SGaist Moved QNetworkRequest out of the struct and creating it just before the get call, seems to be working fine now.

                  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