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. Various crashes when using QNetworkAccessManager
Forum Updated to NodeBB v4.3 + New Features

Various crashes when using QNetworkAccessManager

Scheduled Pinned Locked Moved General and Desktop
qnetworkaccessmqdialog
13 Posts 3 Posters 6.2k Views 2 Watching
  • 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.
  • K Offline
    K Offline
    koahnig
    wrote on last edited by
    #4

    Sorry, the same is true for managerPHP. Remove this delete as well in your destructor.

    Vote the answer(s) that helped you to solve your issue(s)

    T 1 Reply Last reply
    0
    • K koahnig

      Sorry, the same is true for managerPHP. Remove this delete as well in your destructor.

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

      @koahnig
      The same problem persists. It will crash after closing the dialog.

      K 1 Reply Last reply
      0
      • T testus

        @koahnig
        The same problem persists. It will crash after closing the dialog.

        K Offline
        K Offline
        koahnig
        wrote on last edited by
        #6

        @testus
        Theoretically there might be still a signal on its way, while you are destructing your object. However, I consider this as not possible.
        Did you do rebuild?
        To be save you can add before rebuild a qmake run. That makes sure that all is uptodate.

        Vote the answer(s) that helped you to solve your issue(s)

        T 1 Reply Last reply
        0
        • K koahnig

          @testus
          Theoretically there might be still a signal on its way, while you are destructing your object. However, I consider this as not possible.
          Did you do rebuild?
          To be save you can add before rebuild a qmake run. That makes sure that all is uptodate.

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

          @koahnig
          I did a clean build. I do wait until I receive the message from openedPHP() before I close the QDialog. Sometimes it will work and I can click the button and close the QDialog afterwards without a crash. But thats quite rare. Other times it will immediately crash when on_buttonUpload_clicked() is called. But like I said, most times it crashes after closing the QDialog after having clicked the button.

          K 1 Reply Last reply
          0
          • T testus

            @koahnig
            I did a clean build. I do wait until I receive the message from openedPHP() before I close the QDialog. Sometimes it will work and I can click the button and close the QDialog afterwards without a crash. But thats quite rare. Other times it will immediately crash when on_buttonUpload_clicked() is called. But like I said, most times it crashes after closing the QDialog after having clicked the button.

            K Offline
            K Offline
            koahnig
            wrote on last edited by
            #8

            @testus

            I do not see another problem in your code. Possibly it is in another part than the routines you are posting.
            With similar destructors as you implemented with cleaning up the the pointer I faced also unmotivated crash, which I could not explain. So, if you delete other pointers to Qt objects as you do here, you better clean this up. Check out this description of deletelater()

            Vote the answer(s) that helped you to solve your issue(s)

            1 Reply Last reply
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #9

              As @koahnig mentioned there's not much here that could cause a crash. I suspect it's something in the code that creates and shows that dialog. Can you post this part?

              I have also two comments to this discussion:

              1. Contrary to what @koahnig said you should definitely delete the ui like in your original post! The ui is not a QObject and its lifetime is not managed by Qt parent-child mechanism.
                The comment about deleting managerPHP is true though. You're giving it a parent (this), so don't delete it manually as this will crash the app.

              2. You are leaking memory. The openedPHP method should take a QNetworkReply* parameter and call deleteLater() on it. It is not deleted automatically.

              K 1 Reply Last reply
              0
              • Chris KawaC Chris Kawa

                As @koahnig mentioned there's not much here that could cause a crash. I suspect it's something in the code that creates and shows that dialog. Can you post this part?

                I have also two comments to this discussion:

                1. Contrary to what @koahnig said you should definitely delete the ui like in your original post! The ui is not a QObject and its lifetime is not managed by Qt parent-child mechanism.
                  The comment about deleting managerPHP is true though. You're giving it a parent (this), so don't delete it manually as this will crash the app.

                2. You are leaking memory. The openedPHP method should take a QNetworkReply* parameter and call deleteLater() on it. It is not deleted automatically.

                K Offline
                K Offline
                koahnig
                wrote on last edited by Chris Kawa
                #10

                @Chris-Kawa
                You are right about ui. I was just following the destructors I have in some code. There ui is no pointer and therefore, there is no delete required.

                Has this been changed lately?
                Those classes have been created with designer, but some time back on Qt 4.

                Vote the answer(s) that helped you to solve your issue(s)

                1 Reply Last reply
                0
                • Chris KawaC Offline
                  Chris KawaC Offline
                  Chris Kawa
                  Lifetime Qt Champion
                  wrote on last edited by Chris Kawa
                  #11

                  @koahnig You can set the wizard behavior in QtCreator in Tools -> Options -> C++ -> Qt Class Generation. Visual Studio add-in gives you this option in class wizard dialog. I moved to Qt5 a long time ago but I vaguely remember the default was the same around Qt 4.7ish. Not sure if it changed somewhere earlier.

                  K 1 Reply Last reply
                  0
                  • Chris KawaC Offline
                    Chris KawaC Offline
                    Chris Kawa
                    Lifetime Qt Champion
                    wrote on last edited by Chris Kawa
                    #12
                    This post is deleted!
                    1 Reply Last reply
                    0
                    • Chris KawaC Chris Kawa

                      @koahnig You can set the wizard behavior in QtCreator in Tools -> Options -> C++ -> Qt Class Generation. Visual Studio add-in gives you this option in class wizard dialog. I moved to Qt5 a long time ago but I vaguely remember the default was the same around Qt 4.7ish. Not sure if it changed somewhere earlier.

                      K Offline
                      K Offline
                      koahnig
                      wrote on last edited by
                      #13

                      @Chris-Kawa
                      OK, thanks for advise. I had checked in the mean time with Qt 5.3 and designer does also do a pointer assignment now.
                      I have started years ago with MSVC and addin. I guess those dialogs are from that time. Never seen this possibility (at least I do not remember).
                      Anyway the thing is the generated code has to work and it does either way. Unfortunately, I step into this trap and giving wrong advise.

                      Vote the answer(s) that helped you to solve your issue(s)

                      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