python segfaulting, MemoryError (PyQt)

Phil Thompson phil at riverbankcomputing.com
Tue Apr 28 09:37:49 EDT 2009


On Tue, 28 Apr 2009 14:54:41 +0200, "Denis L" <no at spam.com> wrote:
> "Phil Thompson" <phil at riverbankcomputing.com> wrote in message 
> news:mailman.4664.1240907352.11746.python-list at python.org...
>> On Tue, 28 Apr 2009 03:53:34 +0200, "Denis L" <no at spam.com> wrote:
>>> 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
>>>
>>> Thanks in advance for any help.
>>
>> Works fine for me with current versions.
>>
>> Phil
> 
> I have noticed that if I do "self.values[option] = QString(value)"
> instead of "self.values[option] = value" in optionChanged I don't get any

> errors.
> 
> Is it perhaps not safe to keep the reference to the lambda QString
> argument? 

It shouldn't make any difference.

Phil



More information about the Python-list mailing list