[PyKDE] Stuck newbie

David Boddie david at boddie.org.uk
Mon Oct 9 22:35:32 BST 2006


On Monday 09 October 2006 09:41:59 +0200, Johannes Graumann wrote:

> Can somebody please give me a hint why the amateurish code below segfaults?
> What am I doing wrong and how to fix it?

[...]

> class ElNotes:
>     def __init__(self,args):
>       self = QtGui.QApplication(args)
>       self.maindialog = uic.loadUi("ElNotes_GUI.ui")
>       self.maindialog._connectSlots()
>       self.maindialog.show()
>       self.exec_()
>     def _connectSlots(self):
>       self.maindialog.connect(self.actionQuit_Ctr_Q,
>                               SIGNAL("clicked()"),
>                               self.slotQuit_Ctr_Qclicked)

[...]

> if __name__=="__main__":
>   ElNotes = ElNotes(sys.argv)

It's slightly unusual to use a class to enter the main loop like this,
but there's nothing actually wrong with this approach. The problem may
be that you're reassigning self in the __init__() method, and the class
doesn't inherit from QApplication.

It would be more correct to subclass QApplication instead:

class ElNotes(QtGui.QApplication):
    def __init__(self,args):
      QtGui.QApplication.__init__(self, args)
      self.maindialog = uic.loadUi("ElNotes_GUI.ui")
      self.maindialog._connectSlots()
      self.maindialog.show()
      self.exec_()
    def _connectSlots(self):
      self.maindialog.connect(self.actionQuit_Ctr_Q,
                              SIGNAL("clicked()"),
                              self.slotQuit_Ctr_Qclicked)

I haven't actually tried this out, but it should work. Let us know whether
it did or not.

David




More information about the PyQt mailing list