[PyKDE] Implementation of KConfigSkeleton::addItemUInt

Michael Franz Aigner amfranz at gmail.com
Wed Sep 1 08:26:07 BST 2004


Subject: Implementation of KConfigSkeleton::addItemUInt

Hello,

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?

--
Michael Franz Aigner




More information about the PyQt mailing list