I think you need to define your roles. See http://doc.qt.nokia.com/4.7-snapshot/qdeclarativemodels.html
down in the section about C++ data models. See also http://doc.qt.nokia.com/4.7-snapshot/qabstractitemmodel.html#setRoleNames Cheers, Henrik On 16. mars 2010, at 20.28, ext Mattias Olausson wrote: > Hi, > > Does anyone have an example project for displaying a QML ListView with a > custom C++ model, for example using QList or QAbstractListModel? I've been > studying the documentation but can't get it to work - however, a QStringList > works. > > The example I'm trying to run is supposed to display a qml ListView using a > QList<DataObject*> as model. > > The DataObject only has one attribute, a QString. It is a registered type > (the lines QML_DECLARE_TYPE(DataObject), QML_DEFINE_TYPE(Data, 1,0, > DataObject, DataObject) and qRegisterMetaType<DataObject>("DataObject") are > added in hopefully appropriate places in the code) so I can instantiate it in > QML successfully. (for example DataObject {name: "Joe"} works) > > The qml ListView displays the correct number of elements, so I know it > reaches the list, but my delegate won't access the roles - I just get > "undefined" prompted where the role (a QString) should be displayed. > > I'm working with the qml snapshot on 4.6.0 since our HW platform is running > on this release. A bug perhaps? > > Best regards > > Mattias Olausson > > > > _______________________________________________ > Qt4-preview-feedback mailing list > [email protected] > http://lists.trolltech.com/mailman/listinfo/qt4-preview-feedback _______________________________________________ Qt4-preview-feedback mailing list [email protected] http://lists.trolltech.com/mailman/listinfo/qt4-preview-feedback
