python segfaulting, MemoryError (PyQt)

D

Denis L

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.

Denis
 
D

Diez B. Roggisch

Denis said:
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.

Diez
 
P

Phil Thompson

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
 
P

Phil Thompson

Denis said:
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
 
D

Diez B. Roggisch

As the documentation of pyqt clearly states, connecting signals doesn't
But it does increase the refcount for lambda slots.

Has that changed? It has been a while, but I've been bitten by this before,
so I was pretty sure about my answer.

Diez
 
P

Phil Thompson

Has that changed? It has been a while, but I've been bitten by this before,
so I was pretty sure about my answer.

Support for lambda slots was add in PyQt v4.1.1 (released December 2006).

Phil
 
D

Denis L

Phil Thompson said:
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?
 
P

Phil Thompson

Phil Thompson said:
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
 
D

Diez B. Roggisch

Phil said:
Support for lambda slots was add in PyQt v4.1.1 (released December 2006).

Unfortunately after I had the chance to play with PyQt for the last time.
Thanks for clarifying!

Diez
 
D

Denis L

Phil Thompson said:
Phil Thompson said:
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

Last idea, C++ declaration of textChanged signal is this:

void textChanged (const QString&text)

would self.values[option] = value store the reference to QString? And if so
is that safe, to access that object after my slot returns?

As far as I can see C++ equivalent would be

QString* pointer = &text; then derferencing that pointer later in the code.
I can see how this could cause problems.

Btw you are using PyQt 4.4.4 correct? What version of python?
 
P

Phil Thompson

Phil Thompson said:
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

Last idea, C++ declaration of textChanged signal is this:

void textChanged (const QString&text)

would self.values[option] = value store the reference to QString? And if so

is that safe, to access that object after my slot returns?

As far as I can see C++ equivalent would be

QString* pointer = &text; then derferencing that pointer later in the code.

I can see how this could cause problems.

If there was a bug with lambda slots it's been fixed by now.
Btw you are using PyQt 4.4.4 correct? What version of python?

PyQt v4.5 snapshot, Python v2.6.2 and v3.0.1.

Phil
 
D

Denis L

If there was a bug with lambda slots it's been fixed by now.

I just tried it and I'm getting the same errors with regular functions.

Could you try running the code bellow? What output you are getting when
barTextChanged is called?

On my system self.foo and text point to the same QString object.

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class Options(QDialog):
def __init__(self):
QDialog.__init__(self)

fooEdit = QLineEdit()
self.connect(fooEdit, SIGNAL('textChanged(QString)'),
self.fooTextChanged)

barEdit = QLineEdit()
self.connect(barEdit, SIGNAL('textChanged(QString)'),
self.barTextChanged)

layout = QVBoxLayout()
layout.addWidget(fooEdit)
layout.addWidget(barEdit)
self.setLayout(layout)

def fooTextChanged(self, text):
self.foo = text

def barTextChanged(self, text):
print self.foo, text, id(self.foo), id(text)

def main(args):
app = QApplication(args)
dialog = Options()
dialog.show()
app.exec_()

if __name__ == '__main__':
main(sys.argv)
 
P

Phil Thompson

I just tried it and I'm getting the same errors with regular functions.

Could you try running the code bellow? What output you are getting when
barTextChanged is called?

On my system self.foo and text point to the same QString object.

I see different objects.

Phil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top