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. QStandardItemModel item ownership
QtWS25 Last Chance

QStandardItemModel item ownership

Scheduled Pinned Locked Moved Solved General and Desktop
qstandarditemmo
4 Posts 3 Posters 501 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.
  • A Offline
    A Offline
    artwaw
    wrote on 7 Mar 2022, 12:47 last edited by
    #1

    Sill question but I found documentation unclear or can't deduce if it is stated there somewhere:
    I have a model with items and so on. Now, I'd like to remove all the items using setRowCount(0); - will memory be released for all QStandardItem* entries properly or do I need to iterate and delete them? (Qt 6.2.3)

    Thanks in advance.
    Artur.

    For more information please re-read.

    Kind Regards,
    Artur

    J 1 Reply Last reply 7 Mar 2022, 12:56
    0
    • A artwaw
      7 Mar 2022, 12:47

      Sill question but I found documentation unclear or can't deduce if it is stated there somewhere:
      I have a model with items and so on. Now, I'd like to remove all the items using setRowCount(0); - will memory be released for all QStandardItem* entries properly or do I need to iterate and delete them? (Qt 6.2.3)

      Thanks in advance.
      Artur.

      J Offline
      J Offline
      JKSH
      Moderators
      wrote on 7 Mar 2022, 12:56 last edited by JKSH 3 Jul 2022, 12:56
      #2

      @artwaw said in QStandardItemModel item ownership:

      Sill question but I found documentation unclear or can't deduce if it is stated there somewhere:
      I have a model with items and so on. Now, I'd like to remove all the items using setRowCount(0); - will memory be released for all QStandardItem* entries properly or do I need to iterate and delete them? (Qt 6.2.3)

      Not a silly question at all! I didn't know the answer either so I went digging.

      Looks like the old QStandardItems are deleted: https://code.woboq.org/qt6/qtbase/src/gui/itemmodels/qstandarditemmodel.cpp.html#_ZN13QStandardItem10removeRowsEii

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      A 1 Reply Last reply 7 Mar 2022, 12:57
      4
      • J JKSH
        7 Mar 2022, 12:56

        @artwaw said in QStandardItemModel item ownership:

        Sill question but I found documentation unclear or can't deduce if it is stated there somewhere:
        I have a model with items and so on. Now, I'd like to remove all the items using setRowCount(0); - will memory be released for all QStandardItem* entries properly or do I need to iterate and delete them? (Qt 6.2.3)

        Not a silly question at all! I didn't know the answer either so I went digging.

        Looks like the old QStandardItems are deleted: https://code.woboq.org/qt6/qtbase/src/gui/itemmodels/qstandarditemmodel.cpp.html#_ZN13QStandardItem10removeRowsEii

        A Offline
        A Offline
        artwaw
        wrote on 7 Mar 2022, 12:57 last edited by
        #3

        @JKSH Thank you!

        For more information please re-read.

        Kind Regards,
        Artur

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 7 Mar 2022, 13:11 last edited by
          #4

          But it's in the documentation for e.g. setItem(): The model takes ownership of the item.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          2

          4/4

          7 Mar 2022, 13:11

          • Login

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