Pyqt4 Nested Classes - "runtimeerror: Underlying C/c++ Object Has Been Deleted"
Solution 1:
Thanks to everyone who tried to answer! Unfortunately no one said what a bunch of crap I wrote! *smile*
My line
is already a widget and I don't need to create itself inside itself. All I had to do is to create layout inside setup_ui
and add widgets to it. Finally it looks like:
classLine(QtGui.QWidget):
def__init__(self, parent=None):
super(Line, self).__init__(parent)
self.setup_ui(parent)
defsetup_ui(self, parent):
line = QtGui.QHBoxLayout(self)
add_button = QtGui.QPushButton()
add_button.setObjectName("add_button")
line.addWidget(add_button)
# to get reference from outside
self.add_button = add_button
defset_controls(self, add_button=True, remove_button=True):
self.add_button.setEnabled(add_button)
Special thanks to nymk and Avaris!
Solution 2:
I could not reproduce an error with the code you showed us (apart from an error about the variable line
not being defined in Line.setup_ui
). If I replaced line
with self
, I got no error.
However, I could get a crash if I set line
to a QWidget
that I created and didn't keep a reference to. In other words, I added
line = QtGui.QWidget()
to Line.setup_ui
, and found that this crashed on the same line of code you reported, complaining that the wrapped C/C++ object had been deleted.
Post a Comment for "Pyqt4 Nested Classes - "runtimeerror: Underlying C/c++ Object Has Been Deleted""