python segfaulting, MemoryError (PyQt)

Phil Thompson phil at riverbankcomputing.com
Tue Apr 28 04:30:26 EDT 2009


On Tue, 28 Apr 2009 09:35:31 +0200, "Diez B. Roggisch"
<deets at nospam.web.de>
wrote:
> Denis L schrieb:
>> Hello,
>> 
>> I'm experiencing odd errors on both windows and linux with the following

>> code:
>> 
>> import sys
>> from PyQt4.QtCore import *
>> from PyQt4.QtGui import *
>> 
>> class Options(QDialog):
>>     def __init__(self, values):
>>         QDialog.__init__(self)
>> 
>>         self.values = values
>> 
>>         fooEdit = QLineEdit(values['foo'])
>>         self.connect(fooEdit, SIGNAL('textChanged(QString)'),
>>                      lambda value: self.optionChanged('foo', value))
>> 
>>         barEdit = QLineEdit(values['bar'])
>>         self.connect(barEdit, SIGNAL('textChanged(QString)'),
>>                      lambda value: self.optionChanged('bar', value))
>> 
>>         layout = QVBoxLayout()
>>         layout.addWidget(fooEdit)
>>         layout.addWidget(barEdit)
>> 
>>         self.setLayout(layout)
>> 
>>     def optionChanged(self, option, value):
>>         self.values[option] = value
>>         print self.values
>> 
>> def main(args):
>>     app = QApplication(args)
>>     values = dict(foo='', bar='')
>>     dialog = Options(values)
>>     dialog.show()
>>     app.exec_()
>> 
>> if __name__ == '__main__':
>>     main(sys.argv)
>> 
>> 
>> If I type a character in fooEdit, another character in barEdit, and then

>> delete the character from barEdit I get an unhandled win32 exception
>> occured
>> in python.exe on windows and segfault on linux.
>> 
>> If I type a character in fooEdit, delete it, and then type a character
in
>>
>> barEdit I get:
>> 
>> {'foo': PyQt4.QtCore.QString(u'a'), 'bar': ''}
>> {'foo': PyQt4.QtCore.QString(u''), 'bar': ''}
>> {'foo': Traceback (most recent call last):
>>   File "L:\home\dev\python\test.py", line 17, in <lambda>
>>     lambda value: self.optionChanged('bar', value))
>>   File "L:\home\dev\python\test.py", line 27, in optionChanged
>>     print self.values
>> MemoryError
>> 
>> I'm using Python 2.5.4 and PyQt 4.4.3-1
> 
> As the documentation of pyqt clearly states, connecting signals doesn't 
> increment the refcount on a passed slot, thus
>   you need to keep a reference to your slots around.

But it does increase the refcount for lambda slots.

Phil



More information about the Python-list mailing list