[PyKDE] Segmentation Fault: new-style objects

Phil Thompson phil at riverbankcomputing.co.uk
Sat Feb 7 11:45:00 GMT 2004


On Thursday 05 February 2004 5:29 pm, Uwe Mayer wrote:
> Hi,
>
> I was asked to report this behaviour to the "PyQt Folks" and this is the
> best adress I could come up with. :)
>
> Using multiple inheritance with one predecessor being a Qt widget and the
> other being a new-style class causes a segmentation fault upon
> instanciating the combined child class.
>
> -- example --
> from qt import QWidget, QApplication
> import sys
>
> class A:
>     def __init__(self):
>         print "in A"
>
> class B(object):
>     def __init__(self):
>         print "in B"
>
> class C(QWidget,A):
>     def __init__(self):
>         QWidget.__init__(self)
>         A.__init__(self)
>         print "in C"
>
> class D(QWidget,B):
>     def __init__(self):
>         QWidget.__init__(self)
>         B.__init__(self)
>
> app = QApplication(sys.argv)
> C() #works
> D() #fails
> -- example --
>
> The versions where this behaviour occurs:
>
> Python 2.3.3
>
> >>> qt.PYQT_BUILD
>
> '180'
>
> >>> qt.PYQT_VERSION
>
> 198656
>
> >>> qt.PYQT_VERSION_STR
>
> '3.8'

This will be "fixed" in tonight's SIP v3 snapshot. It will now raise an 
exception rather than seg fault. If you need to be able to do this then use 
SIP v4.

> Another thing I'd like to report:
> pyuic makes a mistake when compiling the source of Qt Designer interface
> file when the widget in the .ui file contains a toolbar with a Spacer
> object. pyuic "forgetts" a "self." infront of the Toolbar object:
>
> -- snip --
> $ python LMCMain.py
> Traceback (most recent call last):
>   File "LMCMain.py", line 65, in ?
>     main = LMCMain()
>   File "LMCMain.py", line 39, in __init__
>     LMCMainBase.__init__(self, parent, name, fl)
>   File "/home/merkosh/Projekte/LMC/LMC/GUI/LMCMainBase.py", line 1721, in
> __init__
>     QApplication.sendPostedEvents(Toolbar,QEvent.ChildInserted)
> NameError: global name 'Toolbar' is not defined
> -- snip --
>
> The lines in question yield:
> -- snip2 --
>         spacer = QSpacerItem(0,0,QSizePolicy.Expanding,QSizePolicy.Minimum)
>         QApplication.sendPostedEvents(Toolbar,QEvent.ChildInserted)
>         Toolbar.boxLayout().addItem(spacer)
> -- snip2 --
>
> In both cases this should be
>         spacer = QSpacerItem(0,0,QSizePolicy.Expanding,QSizePolicy.Minimum)
>         QApplication.sendPostedEvents(self.Toolbar,QEvent.ChildInserted)
>         self.Toolbar.boxLayout().addItem(spacer)

This will be fixed in tonight's PyQt snapshot.

The extra bug that Ulli noticed is also fixed. (This one is also a bug in uic 
from Qt v3.3.0.)

Thanks,
Phil




More information about the PyQt mailing list