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. Model item cleanup?
Qt 6.11 is out! See what's new in the release blog

Model item cleanup?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 2.9k Views 1 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.
  • J Offline
    J Offline
    jsshapiro
    wrote on last edited by
    #1

    When a model item is added to a model, does the model "own" the item for deletion purposes?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #2

      Which model items are you talking about?

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jsshapiro
        wrote on last edited by
        #3

        For example, when I add a StandardModelItem to a StandardModel. Who is later responsible for deleting the StandardModelItem?

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dangelog
          wrote on last edited by
          #4

          The model you added it into.
          [quote]
          QStandardItemModel::~QStandardItemModel ()

          Destructs the model. The model destroys all its items.
          [/quote]

          Software Engineer
          KDAB (UK) Ltd., a KDAB Group company

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jsshapiro
            wrote on last edited by
            #5

            Thanks. Sorry - I should have read more carefully.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #6

              Caution! The model does not always delete the items!

              If you use one of the takeXX methods, like "QStandardItemModel::takeItem() ":http://doc.qt.nokia.com/4.7/qstandarditemmodel.html#takeItem, the item is removed from the model, but it is not deleted! You get back a pointer (or a list of pointers) to the item(s) and you can reinsert the item in the same or another model or you must delete it manually to avoid a memory leak.

              http://www.catb.org/~esr/faqs/smart-questions.html

              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