I store objects of a custom data type in QStandardListItems. I recover these objects by calling:
i.data(Qt::UserRole + 1).value<LiteReach>();
This only creates a new object in the stack. Any changes I do to them would be temporary.
Is there a way to get the base object stored in itemData so that it could be manipulated directly?
If not what would be the preferred method to change itemData?
I would like not to call setData each time an object is modified since it would consume a lot of resources.
You could use pointers that allow access to the concrete data objects instead of copying the whole data into a QVariant like above.
The problem is that
value()returns a copy of your data. So if you make any modifications, they will be gone as soon as the copy is removed from stack.If you don’t want to use pointers, I guess you’ll have to stick with
setData().