Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-639

TreeWidget Model data items being deleted while they are still in Python scope

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3: Somewhat important
    • Resolution: Invalid
    • Affects Version/s: 5.9, dev
    • Fix Version/s: 5.9
    • Component/s: PySide
    • Labels:
      None
    • Environment:
      Linux

      Python 3.6

      Pyside2 installed from: PySide2-5.11.0a1-5.11.0-cp36-cp36m-linux_x86_64.whl

       

      Description

      When I try to access the data from the Model for a selected item in the tree I get a "Internal C++ object already deleted error" - but as far as I can see I have ensured that I have a current reference to the item data in scope.

      The test case below demonstrates the issue. When the user selects the item from the Tree and then clicks the button the following error is reported:

       

       

      Traceback (most recent call last): File "test_case.py", line 33, in button_clicked self.tree.selectionModel().selection()[0] RuntimeError: Internal C++ object (PySide2.QtCore.QAbstractItemModel) already deleted.

       

       

      Clearly something is going out of scope but I can not see where.

      from PySide2.QtWidgets import (QApplication, QMainWindow, QAbstractItemView,
                                     QPushButton, QVBoxLayout, QGroupBox,
                                     QTreeWidget, QTreeWidgetItem)
      
      
      class MainWindow(QMainWindow):
          def __init__(self):
              super(MainWindow, self).__init__()
      
              self.tree = QTreeWidget(self)
      
              self.button = QPushButton(self, text="Run Tests")
      
              self.vbox = QVBoxLayout(self)
              self.vbox.addWidget(self.tree)
              self.vbox.addWidget(self.button)
      
              self.frame = QGroupBox(self, title="Test &Run")
              self.frame.setLayout(self.vbox)
      
              self.button.clicked.connect(self.button_clicked)
      
              self.setCentralWidget(self.frame)
      
              self.item = QTreeWidgetItem(self.tree)
      
              self.item.setText(0, "list item 1")
      
              self.show()
      
          def button_clicked(self):
              data = self.tree.selectionModel().model().data(
                  self.tree.selectionModel().selection()[0]
              )
      
      
      if __name__ == "__main__":
          app = QApplication([])
          app.mainWindow = MainWindow()
          app.exec_()
      

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            hippysurfer1 hippysurfer1
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes