[PyKDE] Segmentation Fault: new-style objects

Uwe Mayer merkosh at hadiko.de
Fri Feb 6 11:24:00 GMT 2004


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'


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)


I hope you will find this information usefull. If you need any other 
information, please feel free to contact me.

Not to forgett: Thanks für PyQt!

Ciao
Uwe




More information about the PyQt mailing list