you are right guys, it just can not be solved in a better way. I think it should be explained somewhere since this is not a trivial issue, is it?<br><br>cheers,<br>Krystian<br><br><div><span class="gmail_quote">2006/11/21, Giovanni Bajo &lt;
<a href="mailto:rasky@develer.com">rasky@develer.com</a>&gt;:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Krystian Samp wrote:<br>
<br>&gt;&gt; It seems that when you create an item the python object holds a<br>&gt;&gt; reference to it. However, if you assign that item to a hierarchy of<br>&gt;&gt; items (for instance using setParentItem()) the python object loses
<br>&gt;&gt; (or you can say hands over) the reference. This reference still<br>&gt;&gt; exists in the C/C++ level in the hierarchy but only there. So If you<br>&gt;&gt; stop referencing to the parent of the item then the item itself will
<br>&gt;&gt; be destroyed as well. This is weird since you still have a python<br>&gt;&gt; object representing the item but as I said it handed over the<br>&gt;&gt; reference to the C/C++ layer. This is my observation and I think
<br>&gt;&gt; it's not a good behavior of PyQt since you actually have to think<br>&gt;&gt; about C/C++ and the principle I've described.<br><br>Well, you HAVE to know what C++ does anyway. If the C++-side thinks that the<br>
parent owns the ownership of the child, there is nothing PyQt can do to<br>prevehent it. If the C++ side then destroys that item (because eg. the<br>parent kills it), there's nothing PyQt can do to prevent the object from
<br>being deallocate. I'll give you a short example of what I mean:<br><br>class Foo(QWidget):<br>&nbsp;&nbsp;&nbsp;&nbsp;def __init__(self, parent):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; QWidget.__init__(self, parent)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.bar = QWidget(self)<br><br>f = Foo(None)
<br>b = f.bar<br>del f<br># what about b?<br><br>In this case, Python still holds a reference to &quot;b&quot;, but the underlying<br>QWidget in C++ has been destroyed because it was child of &quot;f&quot; and &quot;f&quot; was
<br>destroyed. There's nothing PyQt can do to prehevent this: on the contrary,<br>it *exposes* this behaviour, which is the way QObject's ownership system<br>works.<br><br>In other words, you can't ignore this problem, you must know and understand
<br>QObject lifetime. You can't assume that, since you have a Python reference,<br>the underlying object will stay alive forever.<br>--<br>Giovanni Bajo<br><br></blockquote></div><br>