I'll try to answer my own question, in the hopes that it might benefit someone else.
You definitely need to maintain those QObjects in memory on the C++ side. When I pushed a QList<QObject*> to the model of a ListView, and then later deleted the QList (using qDeleteAll), I got an instant seg fault. There's also some unclear behaviour as to what happens when you clear the ListView of all elements, and then try to delete the QList. I ran into the same problem (seg fault) even though the model was now pointing to something else. So right now I keep track of everything I send to the declarative engine in this manner and then delete it when I exit the program. It's not ideal, but it's the only solution that works for me. Regards, -Pris On Sat, Oct 8, 2011 at 7:21 PM, Pris Matic <[email protected]>wrote: > Hi all, > > I have a question about what exactly happens when you have a > QList<QObject*> in your C++ code, and then you send it to QML with something > like this: > > QVariant Abc::GetObjectList() > { return QVariant::fromValue(m_object_list); } > > Where m_object_list is a QList<QObject*> where the QObjects have slots that > can be directly invoked from QML (imagine using the list for something like > a ListView). > > Does the QML side of things create a copy of the list, or do I have to > maintain it in C++? Ie if m_object_list was cleared after 'GetObjectList' > was called from QML, then would the list still be valid? If I was using a > ListView, would the ListView need to access that QList if it needed to draw > offscreen delegates as they became visible, etc. > > > Regards, > > -Pris >
_______________________________________________ Qt-qml mailing list [email protected] http://lists.qt.nokia.com/mailman/listinfo/qt-qml
