[PyQt] Re: PyQT lost reference (was: Re: PyKDE: KConfigSkeleton
not writing configuration)
Till Gerken
till.gerken at gmail.com
Fri Mar 13 15:53:12 GMT 2009
On 3/13/09, Phil Thompson <phil at riverbankcomputing.com> wrote:
> 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.
The weird thing in this case is that the changes made by
KCoreConfigSkeleton are discarded. Even if I call
KCoreConfigSkeleton::ItemString::setValue(), the referenced QString is
not updated (although it will then be written to disk correctly). This
suggests that two instances of the same QString exist.
I can live with the workaround calling
KCoreConfigSkeleton::ItemString::setValue() and getValue(), but I
wonder where the bug is.
Any pointers would be appreciated.
Till
More information about the PyQt
mailing list