<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Hi</p>
<p>I have the following scenario:
-----------</p>
<p>C++:</p>
<p>class AbstractItem {
AbstractItem(const QString& id);
virtual ~AbstractItem();
};
</p>
<p>class Pool {
void addItem(AbstractItem* item /Transfer/);
AbstractItem* getItem(const QString& id);
};</p>
<p>
</p>
<p>Python:
class Item(AbstractItem):
def __init__(self, id):
AbstractItem.__init__(self, id)
self.value = "value"
def getValue(self):
return self.value
</p>
<p>pool = Pool()
pool.addItem(Item("xyz"))
# ...
item = pool.getItem("xyz")
print(item.getValue()) ### AttributeError: 'Item' object has no attribute 'value'<style type="text/css">
p, li { white-space: pre-wrap; }
</style></p>
<p>-----------
</p>
<p>The issue is that, when I pass the Python-deriver Item instance to the pool, lose the reference to it, and then re-retreive it from the pool, the Item instance will have lost class variables set in the Item __init__ function. As I understand, this is expected, because SIP keeps a python part and a c++ part of each object, and the python part is garbage-collected when the variable gets out of scope. Is there a way to make the above logic work?</p>
<p>Thanks
Sandro</p>
<p>
</p>
<p>
</p>
</body>
</html>