[PyQt] Re: PyQT lost reference (was: Re: PyKDE: KConfigSkeleton not writing configuration)

Phil Thompson phil at riverbankcomputing.com
Fri Mar 13 10:56:52 GMT 2009


On Fri, 13 Mar 2009 11:44:57 +0100, Wolfgang Rohdewald
<wolfgang at rohdewald.de> wrote:
> On Freitag, 13. März 2009, Till Gerken wrote:
> 
>> The QString() that I am passing as reference to the C++ class
>> KCoreConfigSkeleton exists as local variable in my Python class
>> derived from KCoreConfigSkeleton. Now any code that interacts with
>> KCoreConfigSkeleton (C++ or Python) may change this QString instance.
> 
> this is because QString() is mutable while python strings are immutable.
> When dealing with KCoreConfig, do not use QString as local variables,
> always convert explicitly from/to python strings.

No, do exactly the opposite. If you pass a Python string then it will be
converted to a QString under the covers. Any changes to that QString will
then be discarded.

> I wonder what happens with this when the QString will be eliminated
> in PyQt4 as announced. That might break code which relies on 
> QString being mutable.

Which is why eliminating QStrings is an incompatible change and will
require changes to your code.

Phil


More information about the PyQt mailing list