[PyKDE] Implementation of KConfigSkeleton::addItemUInt

Jim Bublitz jbublitz at nwinternet.com
Wed Sep 1 17:50:58 BST 2004


On Wednesday 01 September 2004 00:26, Michael Franz Aigner wrote:
> Subject: Implementation of KConfigSkeleton::addItemUInt

> While using KConfigSkeleton in an application of mine, I noticed that
> KConfigSkeleton::addItemInt/UInt are not working. The value of the
> returned configuration item would change randomly while the
> application runs.

> Tracking down the problem i found out that the C++ code generated by
> sip passes a reference to temporary integer variable to the C++
> function, whereas a reference to a non-temporary variable would be
> needed. This is because KConfigSkeleton remembers the reference and
> uses it later in the application. This reference ends up pointing to
> the location on the stack where this temporary variable once was but
> not anymore is. As this location on the stack is reused, the variable
> the reference is pointing to seemingly changes its value randomly as
> the application runs.

> In search for a way to make KConfigSkeleton::addItemUInt work, i came
> up with the following. The patch is against PyKDE 3.11.3:
> http://amfranz.com/pykde/PyKDE-3.11.3-intref.diff

> Usage would be something like:

> ===
> from kdecore import KConfigSkeleton, UIntRef

> class Preferences(KConfigSkeleton):
>     def __init__(self, *args):
>         KConfigSkeleton.__init__(self, *args)

>         self.some_int_setting = kdecore.UIntRef()
>         self.some_int_setting_property =
> self.addItemUInt('some_int_setting', self.some_int_setting, 1000)

>         print "value is: %d" % self.some_int_setting.getValue()
> ===

> Could you comment on that?
> Maybe there a simpler way to make KConfigSkeleton::addItemInt work,
> w/o introducing a new class, like 'UIntRef' in the above example?

I'll have to look at it in more detail - hopefully later today. 

Jim


	

> --
> Michael Franz Aigner
>
> _______________________________________________
> PyKDE mailing list    PyKDE at mats.imk.fraunhofer.de
> http://mats.imk.fraunhofer.de/mailman/listinfo/pykde




More information about the PyQt mailing list