[PySide] Problem with garbage collection

henry.wede at yahoo.com henry.wede at yahoo.com
Thu Feb 9 00:52:48 CET 2023


Hello,
I am trying to track down a " Internal C++ object (RobotPosition) already deleted" error.  The Internet says that my object is being garbage collected because it falls out of scope.  This is part of a big application so I can't just post a folder of code, but please let me try to explain what I think the problem is.
I have an object that is defined like this:
class RobotPosition(QtWidgets.QListWidgetItem):    '''Class for storing a single robot position.    '''
    def __init__(self):
 super().__init__()
        {snip}

    def __str__(self):
                {snip}
    def setType(self, Type):
                {snip}
    def setName(self, NewName):
                {snip}
    def updateTooltip(self):
                {snip}
Theses objects are created (as shown below) and added to a list widget. 
{snip}Position = ConfigurationClasses.RobotPosition()Position.setType('Intermediate')Position.setName('Position')Position.updateTooltip()

self.ui.listRobotPathPositions.addItem(Position)print(Position.parent()) 
{snip}
The objects display without any issues with the addItem method of the list widget.
The application stores different lists of these objects and uses the same list widget to display them.  If I print these list of objects, they all print nicely due to the __str__ method.  So far, so good.
But when the list widget is cleared (using .clear() ) and the application tries to add a list of objects back to the list widget this message shows up:Internal C++ object (RobotPosition) already deleted

I added the 'print(Position.parent()) ' command above and it says that:AttributeError: 'RobotPosition' object has no attribute 'parent'

So... I think this is the heart of my problem.  Python ( or Qt?) thinks my RobotPosition object has no parent.  However, I think that it does have a parent because it is derived from a QListWidgetItem object that has a parent.  
Could someone please shed some light on what I am doing wrong?
Thanks in advance,Henry





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20230208/33d46bad/attachment.htm>


More information about the PySide mailing list