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

2023-03-28 Thread Friedemann Kleint via PySide

Hi,

could you maybe post a complete, minimal example? Maybe 
QGraphicsSceneEvent.source() needs some ownership modification in the 
binding.


Regards,

Friedemann

--

Friedemann Kleint
The Qt Company GmbH
___
PySide mailing list
PySide@qt-project.org
https://lists.qt-project.org/listinfo/pyside


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

2023-03-27 Thread henry.wede--- via PySide
 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 
 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 +, 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 
  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@qt-project.org
https://lists.qt-project.org/listinfo/pyside


  ___
PySide mailing list
PySide@qt-project.org
https://lists.qt-project.org/listinfo/pyside


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

2023-03-27 Thread henry.wede--- via PySide
 Thank you for the suggestion Alexis.  I tried to connect this signal as 
follows but never saw a message before the error happened.
along with other 
connectionsself.ui.listBlockTypes.destroyed.connect(self.listSource_Destroyed)

another method in the application class...def listSource_Destroyed(self, 
SomeObject): print('Application : listSource_Destroyed')
The list widget is arranged in QtDesigner and the UI file is loaded using:
self.ui =  QtUiTools.QUiLoader().load()
 If I were creating the widget in code then I understand how I might be able to 
let it fall out of scope and be destroyed.  This is so frustrating.
Henry

On Monday, March 27, 2023 at 03:51:01 AM MDT, Alexis Jeandet 
 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 +, 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 
  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@qt-project.org
https://lists.qt-project.org/listinfo/pyside


  ___
PySide mailing list
PySide@qt-project.org
https://lists.qt-project.org/listinfo/pyside


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

2023-03-27 Thread Alexis Jeandet
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 +, 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  name="listBlockTypes") at 0x0187ECDCE040>  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@qt-project.org
> https://lists.qt-project.org/listinfo/pyside

___
PySide mailing list
PySide@qt-project.org
https://lists.qt-project.org/listinfo/pyside