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. QListWidgetItem Destroyer and Release Memory
Forum Updated to NodeBB v4.3 + New Features

QListWidgetItem Destroyer and Release Memory

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 1.6k Views 3 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.
  • I Offline
    I Offline
    isaacEnrique
    wrote on last edited by
    #1

    Best regards

    In the event that the data attribute of a QListWidgetItem is put to a pointer to an object created dynamically (with new): The object in question is destroyed, and the corresponding memory is released when the destroyer of the QListWidgetItem is invoked?

    Thanks for any responses and/or comments

    Isaac Pérez
    Programming is understanding.

    kshegunovK 1 Reply Last reply
    0
    • I isaacEnrique

      Best regards

      In the event that the data attribute of a QListWidgetItem is put to a pointer to an object created dynamically (with new): The object in question is destroyed, and the corresponding memory is released when the destroyer of the QListWidgetItem is invoked?

      Thanks for any responses and/or comments

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @isaacEnrique
      I don't follow, what is the issue?

      Read and abide by the Qt Code of Conduct

      I 1 Reply Last reply
      2
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi
        Do you mean
        if you new your own object, say new MyData
        and then put Mydata into widgetitem via setData

        so the variant holds a pointer to Mydata

        Then it will not be deleted (as far as i can see)
        when QListWidgetItem is deleted.

        I 1 Reply Last reply
        3
        • kshegunovK kshegunov

          @isaacEnrique
          I don't follow, what is the issue?

          I Offline
          I Offline
          isaacEnrique
          wrote on last edited by
          #4

          @kshegunov My post is not a issue, rather it is a practice question. The answer will tell me if I should release the memory myself (with 'delete') or if I can relax and trust the destroyer of QListWidgetItem.

          Isaac Pérez
          Programming is understanding.

          1 Reply Last reply
          0
          • mrjjM mrjj

            Hi
            Do you mean
            if you new your own object, say new MyData
            and then put Mydata into widgetitem via setData

            so the variant holds a pointer to Mydata

            Then it will not be deleted (as far as i can see)
            when QListWidgetItem is deleted.

            I Offline
            I Offline
            isaacEnrique
            wrote on last edited by
            #5

            @mrjj Certainly, I thought so. The documentation did not seem clear about

            Isaac Pérez
            Programming is understanding.

            mrjjM 1 Reply Last reply
            1
            • I isaacEnrique

              @mrjj Certainly, I thought so. The documentation did not seem clear about

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @isaacEnrique
              Well since its stored in a QVariant, it means that
              it can be any value. so it cannot know if a pointer or a "direct" type so
              would be hard for it to delete it.

              But, you might be able to wrap the pointer in a scope smart pointer and when scoped is deleted pr auto, then it deletes the actual Myclass also.

              1 Reply Last reply
              1
              • dheerendraD Offline
                dheerendraD Offline
                dheerendra
                Qt Champions 2022
                wrote on last edited by
                #7

                You need to release the memory on your own if data you placed inside QListWidgetItem is allocated using new.

                Dheerendra
                @Community Service
                Certified Qt Specialist
                http://www.pthinks.com

                1 Reply Last reply
                3

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved