At least I had big problems until I actually made the list QList<QObject*> and 
not QList<MyClass*>.

On Tuesday 16 March 2010, [email protected] wrote:
> The objectlistmodel example illustrates using a QList<QObject*> as the
> model:
> 
> http://qt.gitorious.org/qt/qt/trees/4.7/examples/declarative/objectlistmode
> l
> 
> Regards,
> Martin.
> ________________________________________
> From: [email protected]
> [[email protected]] On Behalf Of Hartz Henrik
> (Nokia-D-Qt/Oslo) Sent: Tuesday, 16 March 2010 8:48 PM
> To: [email protected]
> Cc: [email protected]
> Subject: Re: [Qt4-preview-feedback] Example of c++ model for QML ListView
> 
> 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
> 
> _______________________________________________
> Qt4-preview-feedback mailing list
> [email protected]
> http://lists.trolltech.com/mailman/listinfo/qt4-preview-feedback


-- 
Jan Ekholm
[email protected]
_______________________________________________
Qt4-preview-feedback mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt4-preview-feedback

Reply via email to