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. deleteLater on a member
QtWS25 Last Chance

deleteLater on a member

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 645 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.
  • MegamouseM Offline
    MegamouseM Offline
    Megamouse
    wrote on last edited by Megamouse
    #1

    This is probably a stupid question:

    I have a class with a member progress dialog.
    Whenever I activate a download process the class will spawn that dialog.
    I don't want the dialog to linger between downloads, so I close it when the download was finished and also use deleteLater();

    Now to my question:
    Will the old dialog be properly deleted if I do this at the beginning of the next download:
    m_pdlg = new my_progress_dialog(...);

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

      Hi,

      When calling deleteLater, the object should get deleted the next time the event loop runs.

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

      MegamouseM 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        When calling deleteLater, the object should get deleted the next time the event loop runs.

        MegamouseM Offline
        MegamouseM Offline
        Megamouse
        wrote on last edited by
        #3

        @SGaist can you elaborate?

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

          Basically, deleteLater marks the object for deletion. So next time the Qt event loop runs, it will process that deletion request. This allows for anything pending on that object to be properly cleaned and then the object deleted.

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

          MegamouseM 1 Reply Last reply
          2
          • SGaistS SGaist

            Basically, deleteLater marks the object for deletion. So next time the Qt event loop runs, it will process that deletion request. This allows for anything pending on that object to be properly cleaned and then the object deleted.

            MegamouseM Offline
            MegamouseM Offline
            Megamouse
            wrote on last edited by
            #5

            @SGaist so I just tested with either "m_pdlg->deleteLater()" and "delete m_pdlg" and in both cases the pointer was not a nullptr afterwards (at the beginning of the next download process before using "m_pdlg = new ..."). Is that normal?

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

              Yes it is, raw pointers don't reset themselves to zero.

              If you want that kind of behaviour, use a QPointer or depending on your use-case a QScopedPointer.

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

              MegamouseM 1 Reply Last reply
              2
              • SGaistS SGaist

                Yes it is, raw pointers don't reset themselves to zero.

                If you want that kind of behaviour, use a QPointer or depending on your use-case a QScopedPointer.

                MegamouseM Offline
                MegamouseM Offline
                Megamouse
                wrote on last edited by
                #7

                @SGaist Thank you. I think I can work with that

                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