[Qt-qml] Behaviour when sending QList<QObject*> as QVariant to QML?
Pris Matic
prismatic.project at gmail.com
Mon Oct 10 02:05:05 CEST 2011
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 <prismatic.project at gmail.com>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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20111009/b601fb3f/attachment.html
More information about the Qt-qml
mailing list