It\'s not the first time I am getting the RuntimeError: underlying C/C++ object has been deleted
. I\'ve solved it many times altering my code in a random but in
@charley is completely right, he explained the theory very well. Although in practice this ownership problem can happen in many scenarios, one of the most common is forgetting to call the constructor of the base class while subclassing a QT class - from time to time I always get stuck with this when I start coding from scratch.
Take this very common example of subclassing a QAbstractTableModel:
from PyQt4.QtCore import *
class SomeTableModel(QAbstractTableModel):
def __init__(self, filename):
super(SomeTableModel, self).__init__() # If you forget this, you'll get the
# "underlying C/C++ object has been
# deleted" error when you instantiate
# SomeTableModel.