Identity Versus Value: QExplicitlySharedDataPointer holding data for QObject
Hello. My application contains a mixture of QML and regular Desktop Qt. The QML has a ListModel that displays data held in a QAbstractListModel. The data held by the QAbstractListModel is simply a list of QObjects that I call ListItems. The rest of the application runs off the same data, so the entire application shares that list. I wasn't really a fan of passing pointers around to share stuff since it started getting difficult keeping track of when stuff got deleted, so I moved the ListItems to have explicitly shared data (using QExplicitlySharedDataPointer) thinking I'd pass copies of them around that were all sharing data. That sounded nice and safe.
However, then I ran into the fact that QObjects aren't supposed to be copied (http://qt-project.org/doc/qt-4.8/object.html#qt-objects-identity-vs-value). How should I be doing this? I would appreciate any advice!
In your case, shouldn't all of your application elements rather access your list through the model ? That would avoid having the list playing around and having to synchronize your model (yes, you would be sharing the model rather than the list, but models are made for that kind of logic).
Hope it helps