After a bit of reading, I still don't get this. In the doc, I see that his code is wrong :
renderer.setModel(Source()) renderer.render() because the Source() object will be destroyed too soon. That makes sense. What I don't get is "how wrong" it is. That is, if the Python Source() object is destroyed by Python, then does it mean that the reference that is still present in the renderer is wrong (i.e. it has a pointer to some memory that was freed and that may blow up as soon as renderer tries to reference that ememory) ? I don't see any other explanation, but I want to be sure. If it's because of that then is there somebody who has some experience in debugging that ? I've set up valgrind but I'm not sure it will bring in systematic result. After all, if "renderer" never uses the dangling pointer, then valgrind will never see anything wrong... Am I right (this would save me some frustration :-)) Stefan > Well, > > Not that I have figured out how to fix my code, but I did find out the > documentation that explains that in *great* details (and in a rather clear > way). It's there for those who are still looking for : > > pyside/shiboken/doc/ownership.rst > > I'm a little bit ashamed of not finding this earlier > > stF > > > On Mon, Jan 09, 2012 at 10:36:32PM +0100, S. Champailler wrote: > > Dear mailing list, > > > > In my python code, I usually create QStandardItem with some data, but now I > > realize it may be plain wrong : > > > > > > def make_simple_model(my_data) > > model = QtGui.QStandardItemModel(1, 1) > > > > item = QtGui.QStandardItem() > > item.setData(my_data, Qt.UserRole) > > model.setItem(0, 0, item) # Model takes ownership of the Item (if I > > understand Qt's doc well) > > > > return model > > > > my_data = ... # some kind of Python object > > model = make_simple_model(my_data) > > > > # After this, Python has lost track of my data > > my_data = None > > > > # This one is correct, because model is still tracked by Python and the > > item is owned by the model > > item = model.item(0,0) > > > > # But this is dangerous (because the data has been lost) > > item.data( Qt.UserRole) > > > > > > > > If I got the "PySide pitfalls" page well, this code is wrong : my_data got > > lost (last line of the code) and therefore, the QStandardItem UserRole data > > is a dangling p\ > > ointer... > > > > Is my interpretation correct ? If so, I'd be happy to add this to the > > "pitfalls" page. Although that page does explain the issue, somehow, I > > thought this code was cor\ > > rect until now (it worked thousands of times) => maybe other developpers > > may have the same misunderstanding. > > > > Thx, > > > > Stefan > > > > > > > > _______________________________________________ > > PySide mailing list > > PySide@lists.pyside.org > > http://lists.pyside.org/listinfo/pyside > _______________________________________________ > PySide mailing list > PySide@lists.pyside.org > http://lists.pyside.org/listinfo/pyside _______________________________________________ PySide mailing list PySide@lists.pyside.org http://lists.pyside.org/listinfo/pyside