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. Do I need to call deleteLater() function if QTreeView has widget ownership?

Do I need to call deleteLater() function if QTreeView has widget ownership?

Scheduled Pinned Locked Moved Solved General and Desktop
qtreeviewqstandarditemmosetindexwidgetremoverowdeletelater
5 Posts 2 Posters 1.1k 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.
  • Y Offline
    Y Offline
    Yash001
    wrote on 14 Jan 2021, 20:03 last edited by
    #1

    Hello,

    I am using QTreeView and QStandardItemModel to represent some data on Table. While representing the data I try to show some widget on table using function void QAbstractItemView::setIndexWidget(const QModelIndex &index, QWidget *widget). It is show correctly.

    Now main question is that if user try to set the new data on table at that time I am removing all previous data using bool QAbstractItemModel::removeRow(int row, const QModelIndex &parent = QModelIndex()).

    Do I require to call deleteLater() function while removing data? Or removing row from model is automatically delete the widget?

    auto wdg = treeWidget->indexWidget(index);
    wdg->disconnect();
    wdg->deleteLater();
    
    
    J 1 Reply Last reply 14 Jan 2021, 20:05
    0
    • Y Yash001
      14 Jan 2021, 21:30

      Sorry For asking silly question. Here I got my ans RemoveRow From Model
      void QStandardItem::removeRow(int row)

      J Offline
      J Offline
      JonB
      wrote on 15 Jan 2021, 07:00 last edited by
      #5

      @Yash001
      When items are removed from a model the view will update to reflect the new state. Widgets you have added via setIndexWidget() which are no longer present will be deleted by Qt infrastructure without you needing to delete them or disconnect from signals.

      1 Reply Last reply
      2
      • Y Yash001
        14 Jan 2021, 20:03

        Hello,

        I am using QTreeView and QStandardItemModel to represent some data on Table. While representing the data I try to show some widget on table using function void QAbstractItemView::setIndexWidget(const QModelIndex &index, QWidget *widget). It is show correctly.

        Now main question is that if user try to set the new data on table at that time I am removing all previous data using bool QAbstractItemModel::removeRow(int row, const QModelIndex &parent = QModelIndex()).

        Do I require to call deleteLater() function while removing data? Or removing row from model is automatically delete the widget?

        auto wdg = treeWidget->indexWidget(index);
        wdg->disconnect();
        wdg->deleteLater();
        
        
        J Offline
        J Offline
        JonB
        wrote on 14 Jan 2021, 20:05 last edited by
        #2

        @Yash001 said in Do I need to call deleteLater() function if QTreeView has widget ownership?:

        setIndexWidget

        https://doc.qt.io/qt-5/qabstractitemview.html#setIndexWidget says:

        Sets the given widget on the item at the given index, passing the ownership of the widget to the viewport.

        Y 2 Replies Last reply 14 Jan 2021, 20:42
        1
        • J JonB
          14 Jan 2021, 20:05

          @Yash001 said in Do I need to call deleteLater() function if QTreeView has widget ownership?:

          setIndexWidget

          https://doc.qt.io/qt-5/qabstractitemview.html#setIndexWidget says:

          Sets the given widget on the item at the given index, passing the ownership of the widget to the viewport.

          Y Offline
          Y Offline
          Yash001
          wrote on 14 Jan 2021, 20:42 last edited by
          #3

          @JonB Yes I know QTreeview has ownership of widget. If I will remove the row using model function then widget will delete automatically or not ?

          1 Reply Last reply
          0
          • J JonB
            14 Jan 2021, 20:05

            @Yash001 said in Do I need to call deleteLater() function if QTreeView has widget ownership?:

            setIndexWidget

            https://doc.qt.io/qt-5/qabstractitemview.html#setIndexWidget says:

            Sets the given widget on the item at the given index, passing the ownership of the widget to the viewport.

            Y Offline
            Y Offline
            Yash001
            wrote on 14 Jan 2021, 21:30 last edited by
            #4

            Sorry For asking silly question. Here I got my ans RemoveRow From Model
            void QStandardItem::removeRow(int row)

            J 1 Reply Last reply 15 Jan 2021, 07:00
            0
            • Y Yash001
              14 Jan 2021, 21:30

              Sorry For asking silly question. Here I got my ans RemoveRow From Model
              void QStandardItem::removeRow(int row)

              J Offline
              J Offline
              JonB
              wrote on 15 Jan 2021, 07:00 last edited by
              #5

              @Yash001
              When items are removed from a model the view will update to reflect the new state. Widgets you have added via setIndexWidget() which are no longer present will be deleted by Qt infrastructure without you needing to delete them or disconnect from signals.

              1 Reply Last reply
              2

              5/5

              15 Jan 2021, 07:00

              • Login

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