Howdy,<div>I have found that somewhere between 4.8.3 and 4.9.6, calling QTreeWidgetItem.addChild(item) no longer creates a reference to the specified item (or, at least that is my best guess as to what's going on). I noticed this because I often assign custom attributes to these items and found that the attributes go missing under 4.9.6 if I don't keep an explicit reference to the item. </div>
<div><br></div><div>Here's an example from 4.8.3:</div><div><br></div><div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div>>>> from PyQt4.QtGui import *</div><div>>>> app = QApplication([])</div>
<div>>>> tree = QTreeWidget()</div><div>>>> item = QTreeWidgetItem(["Item"])</div><div>>>> item.attr = "test"</div><div>>>> tree.invisibleRootItem().addChild(item)</div>
<div>>>> del item </div><div>>>> import gc</div><div>>>> gc.collect()</div><div>0</div><div>>>> tree.topLevelItem(0).attr</div><div>'test'</div></div><div><br></div></blockquote>
..and the same under 4.9.6:</div><div><br></div><div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div>>>> from PyQt4.QtGui import *</div><div>>>> app = QApplication([])</div><div>
>>> tree = QTreeWidget()</div>
<div>>>> item = QTreeWidgetItem(["Item"])</div><div>>>> item.attr = "test"</div><div>>>> tree.invisibleRootItem().addChild(item)</div><div>>>> del item </div><div>>>> import gc </div>
<div>>>> gc.collect()</div><div>0</div><div>>>> tree.topLevelItem(0).attr</div><div>Traceback (most recent call last):</div><div> File "<stdin>", line 1, in <module></div><div>AttributeError: 'QTreeWidgetItem' object has no attribute 'attr'</div>
</div><div><br></div></blockquote><div>Questions are:</div>1) Is this a bug, or was the change deliberate?</div><div>2) Does this apply only to QTreeWidgetItem, or are there similar changes elsewhere I should watch out for?</div>
<div><br></div><div><br></div><div>Thanks!</div><div>Luke</div><div><br></div>