PyQt4 - "RuntimeError: C / C Base Object Deleted"

I keep getting this RuntimeError, which I'm not sure how to fix. Here is what I am trying to do. I want to update this QTableWidget dynamically when I click on various elements in my QTreeView. For the most part, my code works, unless I click on my second element and I need to update QTableWidgt when I run this "RuntimeError: The underlying C / C object has been deleted." Here is a snippet of my code:

def BuildTable( self ): ... for label in listOfLabels : attr = self.refAttr[label] self.table.setItem(row, 0, QtGui.QTableWidgetItem( label ) ) tableItem = QtGui.QTableWidgetItem( str(attr.GetValue()) ) self.table.setItem(row, 1, tableItem ) someFunc = functools.partial( self.UpdateValues, tableItem, label ) QtCore.QObject.connect(self.table, QtCore.SIGNAL('itemChanged(QTableWidgetItem*)'), someFunc) def UpdateValues(self, tableItem, label): print '--------------------------------' print 'UPDATING TEXT PROPERTY VALUE!!!' print tableItem.text() print label 

The compiler complains about errors in the string "print tableItem.text ()"

thanks!

+4
source share
1 answer

I believe the problem is that you bind the callback to the QTableWidget element and make a lot of connections (bad). Items are subject to change. Thus, they can be removed by making your callback dead.

What you want is to simply give the itemChanged signal to tell you which item has changed the moment it happens.

 self.table = QtGui.QTableWidget() ... # only do this once...ever...on the init of the table object QtCore.QObject.connect( self.table, QtCore.SIGNAL('itemChanged(QTableWidgetItem*)'), self.UpdateValues ) 

And then in your SLOT it will receive an element:

 def UpdateValues(self, tableItem): print '--------------------------------' print 'UPDATING TEXT PROPERTY VALUE!!!' print tableItem.text() 
+1
source

All Articles