[PyQt] Strangeness with signals and slots in PyQt4 QLineEdit

Johannes Lochmann (gmail) johannes.lochmann at googlemail.com
Thu Aug 16 17:41:25 BST 2007

On Thursday 16 August 2007 16:20, David Boddie wrote:
> On Thu Aug 16 14:57:37 BST 2007, Johannes Lochmann wrote:

Hello David!

Thank you for the quick and thorough response - that cleared things up mighty!

> In the slots in your Widget class, you're just assigning the "txt" values
> to the attributes in the instance of the Data class:
> [...]
> In C++, this would work perfectly because QString objects are copied when
> they are modified, so your copies in the "data" object will be safe.
> In Python, each QString is simply bound to the "a", "b" and "c" attributes.
> When each slot returns, the QString is still referenced, but could be
> changed elsewhere, and the "copy on write" semantics of Qt don't apply.

OK, now knowing this particular detail made everything clear!

> Basically, you have to explicitly copy the "txt" values passed to the
> slots:
> [...]
>           self.data.a = QString(txt)        # or use unicode(txt)

As I have to convert everything to utf-8 for database storage this is no big 

Thank you for your quick help!


More information about the PyQt mailing list