Question

I'm trying to avoid the well-known PyQt Runtime Error when the underlying C/C++ object is deleted:

http://www.riverbankcomputing.com/pipermail/pyqt/2009-April/022809.html

PyQt4 - "RuntimeError: underlying C/C object has been deleted"

PyQt4 nested classes - "RuntimeError: underlying C/C++ object has been deleted"

PyQt: RuntimeError: wrapped C/C++ object has been deleted

Every one of my subclasses calls the super() method and therefore the base classes are properly constructed.

Still, I get this error and am wondering if it is due to the fact that I'm adding a QComboBox widget to a QTreeWidgetItem (using the setItemWidget() method of a QTreeWidget) but I cannot set the parent as the QTreeWidgetItem that contains it. When I try, I get the following error:

TypeError: QComboBox(QWidget parent=None): argument 1 has unexpected type 'QTreeWidgetItem'

Of course, I can either omit the parent in the constructor or pass the QTreeWidget as the parent, but I think I need to reference the correct parent.

I have subclassed the QComboBox and in my subclass it runs some basic operations on the QTreeWidget, but as soon as I enter the methods of my subclassed QComboBox, the underlying C object for the parent QTreeWidgetItem containing the QComboBox is deleted (which is why I'm thinking its something to do with setting the parent of the QComboBox).

I understand 9 times out of 10 the runtime error is due to not constructing the base class. But with that ruled out, how else can the error occur? Could it be due to not referencing the correct parent?

EDIT

I'm using the QComboBox to signal when a new combobox selection was made. Upon a new selection, it adds that selected value to a PyXB XML node. Interestingly, this issue only occurs if I append the value to the PyXB class binding storing the information permanently in an XML file. In otherwords, if that part of the code doesn't run I dont get the error - its only when the code runs the PyXB operation for appending a value to an XML node binding...

Was it helpful?

Solution

I usually avoid that kind of errors keeping a reference on my class to all the objects susceptible of being deleted like your QComboBox so try something like self.comboBoxHolder = QComboBox(...) when you create it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top