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.
  • artwawA Offline
    artwawA Offline
    artwaw
    wrote on 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

    JKSHJ 1 Reply Last reply
    0
    • artwawA artwaw

      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.

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by JKSH
      #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

      artwawA 1 Reply Last reply
      4
      • JKSHJ JKSH

        @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

        artwawA Offline
        artwawA Offline
        artwaw
        wrote on last edited by
        #3

        @JKSH Thank you!

        For more information please re-read.

        Kind Regards,
        Artur

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 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

          • Login

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