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

Reply via email to