PyQt4 - “RuntimeError: underlying C/C object has been deleted”

后端 未结 1 1727
一生所求
一生所求 2021-01-20 01:19

I keep getting this RuntimeError which I\'m not sure how to fix. Here\'s what I\'m trying to accomplish. I want to update this QTableWidget with values dynamically as I\'m

相关标签:
1条回答
  • 2021-01-20 01:45

    I believe the issue is that you are binding up a callback with a QTableWidget item and making many many connections (bad). Items can change. Thus, they can be deleted making your callback dead.

    What you want is to just let the itemChanged signal tell you what item 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 the item:

    def UpdateValues(self, tableItem):
        print '--------------------------------'
        print 'UPDATING TEXT PROPERTY VALUE!!!'
        print tableItem.text()
    
    0 讨论(0)
提交回复
热议问题