Skip to main content
edited tags
Link
prapin
  • 7.1k
  • 5
  • 32
  • 59
Source Link

Does QStandardItemModel take ownership of items when using appendRow()?

In my Qt application, I'm dynamically creating QStandardItem objects and adding them to a QStandardItemModel using appendRow():

auto* item = new QStandardItem("text"); model->appendRow(item); // or appendRow(rowList) 

I know that Qt often uses parent-child object hierarchies for memory management, but I couldn't find explicit documentation confirming that QStandardItemModel takes ownership of the items passed to appendRow().

My model (m_GenerateProgramModel) is a class member variable, and I'm creating items on the heap with new. Do I need to manually delete these items, or is their lifetime managed by the model?

Specifically:

Will the model automatically delete the items when it is destroyed? Is it safe to rely on this behavior, or should I track and delete items manually? I want to avoid memory leaks or double-deletion crashes.

Thanks!