Python: RuntimeError: super-classe __init __ () de% S nunca foi chamado
Eu tentei fazer alguma operação (setParent
) em um objeto em Python (uma instância de uma classe que herda de uma classe diferente - para ser específico,QtGui.QLabel
), mas durante o tempo de execução o erro acima foi levantado. O objeto em si teve alguns campos com conteúdo real (verificado na depuração), mas por algum motivo eu não consegui "usá-lo". O que significa o erro e como posso corrigi-lo? Para algumas informações adicionais, devo dizer que o objeto foi retornado de um método estático antes de tentar fazer essa operação nele.
A subclasse tem um__init__()
função própria:
def __init__(self, image, father):
super(AtomicFactory.Image, self).__init__(father)
self.raw_attributes = image.attributes
self.attributes = {}
father.addChild(self)
self.update()
Agora eu escrevi um código similar, simples, que tinha o mesmo erro na linhawidget.setParent(mw)
quando a janela foi movida.
#!/usr/bin/env python
import sys
import copy
from PyQt4 import QtCore, QtGui
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
main_widget=QtGui.QWidget()
widget = QtGui.QPushButton('Test')
widget.resize(640, 480)
widget.setParent(main_widget)
widget.move(0, 0)
widget2=QtGui.QPushButton('Test2')
widget2.i=0
widget2.resize(600, 200)
widget2.setParent(main_widget)
widget2.move(640, 0)
def onResize(event):
print event
mw=copy.deepcopy(main_widget)
widget.setParent(mw)
widget2.setParent(mw)
widget.move(0, 0)
widget2.move(640, 480)
main_widget_width=main_widget.width()
widget_width=widget.width()
width2=main_widget_width-widget_width
height2=widget2.height()
widget2.resize(width2, height2)
widget2.move(640, 0)
main_widget.resizeEvent=onResize
def onClick():
size=(widget2.width(), widget2.height())
if(widget2.i%2==0):
widget2.resize(int(size[0]/2), int(size[1]/2))
else:
widget2.resize(size[0]*2, size[1]*2)
widget2.i+=1
QtCore.QObject.connect(widget, QtCore.SIGNAL('clicked()'), onClick)
main_widget.show()
sys.exit(app.exec_())
Qual era o problema?