[PyQt] PyQT lost reference (was: Re: PyKDE: KConfigSkeleton not
writing configuration)
Till Gerken
till.gerken at gmail.com
Wed Mar 11 18:55:31 GMT 2009
Hello,
I have debugged the issue that I sent an email about yesterday some
more. I noticed the following:
- modifying a KCoreConfigSkeleton::ItemString value does not write
this value to disk on KCoreConfigSkeleton::writeConfig()
- however, calling KCoreConfigSkeleton::ItemString::setValue() causes
the value to be updated correctly.
I have attached an updated version of the script that illustrates
this, with the method setSimpleThing() on line 36 being the crucial
part:
def setSimpleThing(self, simpleThing):
# BUG: This does not update the KConfigItem value
self._simpleThing = simpleThing
# BUG: The explicit setting however, does.
self._simpleThingKC.setValue(simpleThing)
I found this when looking at KCoreConfigSkeleton::ItemString:
void KCoreConfigSkeleton::ItemString::writeConfig( KConfig *config )
{
if ( mReference != mLoadedValue ) // WABA: Is this test needed?
{
KConfigGroup cg(config, mGroup );
if ((mDefault == mReference) && !cg.hasDefault( mKey))
cg.revertToDefault( mKey );
else if ( mType == Path )
cg.writePathEntry( mKey, mReference );
else if ( mType == Password )
cg.writeEntry( mKey, KStringHandler::obscure( mReference ) );
else
cg.writeEntry( mKey, mReference );
}
}
The first line (mReference!=mLoadedValue) is where PyQt "fails".
mReference is of type QString& and is supposed to point to the value
that gets passed to KCoreConfigSkeleton::addItemString:
[Python Code]
myString = QString("foo")
KCoreConfigSkeleton::addItemString("bar", myString, "barDefaultValue")
At this point, mReference points to myString and
mReference==mLoadedValue. Now, in Python:
myString = QString("bar")
At this point, mReference still seems to contain or point to a string
"foo", which causes the check in
KCoreConfigSkeleton::ItemString::writeConfig() to fail.
My assumption is (I do not have any knowledge about PyQt's inner
workings) that the Python string and the QString copy live at
different positions in memory, even though they are supposed to be
passed by reference. This behavior also does not change when using
QString() instances directly in the Python code. (I adjusted my
example from yesterday accordingly)
However, at least when using QStrings directly from Python, I would
assume the reference to be passed correctly to KCoreConfigSkeleton so
that it catches any updates inside its code. Is this assumption wrong
or is it a bug in PyQt/PyKDE?
I am using the bindings packaged in Kubuntu, version 4:4.2.1-0ubuntu1~intrepid2.
Thanks,
Till
On 3/10/09, Till Gerken <till.gerken at gmail.com> wrote:
> Hello,
>
> I have a problem with KConfigSkeleton not writing its configuration to
> disk when calling KCoreConfigSkeleton::writeConfig(). The odd thing
> about this is that it works when being used together with
> KConfigDialog and KConfigDialogManager, in which case the
> configuration file is written correctly.
>
> I have attached a small sample illustrating this behavior. When run,
> the value that is entered in the configuration widget will be written
> to disk. However, the value that is specified in
> MyConfigMain.queryClose() is not written.
>
> Is this a bug in PyKDE or am I missing something?
>
> Thanks,
>
> Till
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: configtest.py
Type: text/x-python
Size: 2918 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090311/4d5c3356/configtest.py
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mycfg.ui
Type: application/x-designer
Size: 647 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090311/4d5c3356/mycfg.bin
More information about the PyQt
mailing list