Right now if you want to access data in your model in script, you will need to 
add methods to your model to allow that.

For the specific case of showing data from the currentItem, you can expose the 
model data, e.g.

ListView {
    Id: list
    delegate: Text {
        property variant data: model
        text: name
    }
}
Text { text: list.currentItem.data.name }

BR,
Martin.

> -----Original Message-----
> From: qt-qml-boun...@trolltech.com [mailto:qt-qml-boun...@trolltech.com] On
> Behalf Of ext Jan Ekholm
> Sent: Wednesday, 1 December 2010 4:55 PM
> To: qt-qml@trolltech.com
> Subject: [Qt-qml] Accessing a QAbstractItemModel in QML outside a view
> 
> 
> Hi,
> 
> The subject says it all, apart from the context. Accessing a QAIM in a view 
> (such
> as
> a ListView) is all nicely documented and works as expected. However, how can I
> access
> the same exposed C++ model outside a view? In my case I want to show a list of
> data and
> next to the list have some Text/Image items with more information about the
> selected item
> in the view. Totally normal stuff.
> 
> Getting the index of the selected row is easy, the view gives me that. 
> Getting the
> model
> instance is also easy, it's in the root context. However, getting data out of 
> the
> model seems
> to be impossible. I've tried all kinds of ways to access the data but none 
> works.
> However, if
> I look here:
> 
> http://doc.trolltech.com/4.7/qdeclarativemodels.html#accessing-views-and-models-
> from-delegates
> 
> it's seems that delegates can even write data to a model. This gives a 
> somewhat
> perverse
> situation where you can inside delegates read and write to models but outside 
> a
> delegate
> you can't even read data.
> 
> So, this can't possibly be the case and there's something my thick brain just 
> does
> not grok?
> I mean, models are one of the few ways you can get real data into a QML
> document, and not
> being able to actually access it makes it all feel somewhat silly. I can make 
> extra
> methods
> on my subclassed QAIM on the C++ side to get data, but the point is that I 
> should
> not have
> to do that, it ought to just work.
> 
> Someone please give me some RTFM resource.
> 
> Best regards,
>     Jan Ekholm
> 
> --
> Jan Ekholm
> jan.ekh...@smultron.net
> 
> 
> 
> 
> _______________________________________________
> Qt-qml mailing list
> Qt-qml@trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-qml

_______________________________________________
Qt-qml mailing list
Qt-qml@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-qml

Reply via email to