[Tutor] PyQt segfault
Tiago Saboga
tiagosaboga at terra.com.br
Sat Dec 1 19:12:01 CET 2007
On Sat, Dec 01, 2007 at 01:04:04AM +0100, David Boddie wrote:
> Something like that, yes. The internal character data becomes invalid, but
> there's still a reference to the QString object.
>
> Here's the original code posted by Tiago:
>
> > class Combobox(QtGui.QDialog):
> > def __init__(self):
> > QtGui.QDialog.__init__(self)
> > self.ui = Ui_Dialog()
> > self.ui.setupUi(self)
> >
> > self.connect(self.ui.comboBox, QtCore.SIGNAL("activated(QString)"),
> > self.save)
> > def save(self, qstring):
> > # Here it works:
> > #Aux.mystring = unicode(qstring)
> > Aux.mystring = qstring
>
> The correct way to handle this is commented out: to take a copy of the data,
> as you pointed out. This could be done by converting it to a Python unicode
> object, as shown, or by copying the QString:
>
> Aux.mystring = QString(string)
>
> [Off topic, but PyQt-related: You need to explicitly copy value types with
> PyQt because the semantics of copying objects with Python are different to
> those for copying Qt's value classes in C++. In Python, you just bind an
> object to a name, but the equivalent assignment in C++ is basically just
> creating an additional reference to the same object.]
If I understand that correctly, my Aux.mystring is pointing to the
same object passed by QtCore.SIGNAL, which is being garbage-collected?
But the reference in Aux.mystring should not be enough to keep the
object around?
Thanks,
Tiago.
More information about the Tutor
mailing list