[PySide] Internal C++ object (PySide2.QtWidgets.QListWidget) already deleted

henry.wede at yahoo.com henry.wede at yahoo.com
Tue Mar 28 00:31:46 CEST 2023


 Hello,
So... I don't understand why this is happening but I finally figured out what was causing the problem.  Somehow I am not using drag and drop correctly.
I drag an item from a QListWidget and drop it onto a QGraphicsScene.  In the graphics scene events, I was checking that the event.source() was not None.  This was causing the problem where the list widget C++ object was deleted.  If I even print the event.source() then the error happens.
Here are the graphic scene events:
 def ProcessFlowScene_dragMove(self, Event): #print('Application : ProcessFlowScene_dragMove') pass
 def ProcessFlowScene_dragEnter(self, Event): print('Application : ProcessFlowScene_dragEnter') print(type(Event)) #print(Event.source() )  <--- This is what causes the error
 Event.acceptProposedAction()
 def ProcessFlowScene_drop(self, Event):
 # Make sure that the object dropped originated from inside the program #if Event.source() == None: return

 X = Event.scenePos().x() Y = Event.scenePos().y()                ... and other stuff happens here

I suspect that the custom objects (derived from QListWidgetItem) in the list widget are not created properly.  Still not sure why this this would blow up the list widget instead of the list widget item, but there are a lot of things in life that I don't understand :)
Henry


    On Monday, March 27, 2023 at 03:51:01 AM MDT, Alexis Jeandet <alexis.jeandet at member.fsf.org> wrote:  
 
 Hello Henry,
I usually get this error when I forget to keep an active reference on one object from Python.Then since QListWidget inherits QObject, you can connect something to its "destroyed" signal to see when it gets deleted.https://doc.qt.io/qt-6/qobject.html#destroyed
Alexis.On Mon, 2023-03-27 at 03:26 +0000, henry.wede--- via PySide wrote:
Hello all,
I've spent hours trying to figure out a solution to this and I just don't understand what is happening.
The GUI has a QListWidget that contains some objects that subclass QListWidgetItem.  The user can drag these onto a QGraphicsScene and then all kinds of wonderful stuff happens.  And it always works the first time that and object is dropped.  The second time it reports that "Internal C++ object (PySide2.QtWidgets.QListWidget) already deleted".  Not an object in the list, but the list itself!  
It gets even stranger because I added print statements at the start and end of the GraphicsScene drop event.  The first time an item is dropped both print statement print the object as expected.  Specifically, print(self.ui.listBlockTypes) displays <PySide2.QtWidgets.QListWidget(0x187ec2beac0, name="listBlockTypes") at 0x00000187ECDCE040>  so the code in the drop event shouldn't be doing any damage.  
But after the first drop, when I click on an item in the ListWidget (which also has the same print statement) then it reports the error.  How can that be?  It seems that the last line of code that is run in the drop event prints that the ListWidget exists and then the very next line that runs in the ListWidget currentItemChanged event prints an error.
Does anyone have a suggestion?
By the way, I know it would be easier if I could trim down a small program that would display the problem but this is fairly sizable program and that sounds like many hours of work.  
Thanks for your help,
Henry
_______________________________________________
PySide mailing list
PySide at qt-project.org
https://lists.qt-project.org/listinfo/pyside


  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20230327/667b3908/attachment-0001.htm>


More information about the PySide mailing list