Sorry I initially misunderstood your post. model does not have property count, so I think you can use, ListView.count<http://doc.qt.nokia.com/latest/qml-listview.html#count-prop>property : slideshowScope.count instead of model.count should do the trick,
On Sun, May 29, 2011 at 12:05 PM, vineeth <[email protected]> wrote: > Hi, > You can find the example of using a qabstractlistmodel here : > http://doc.trolltech.com/4.7.1/declarative-modelviews-abstractitemmodel.html > You can access the imagePath as model.imagePath, i.e in Image element, > source:model.imagePath should set the path. > HTH, > --vineeth > > > > On Fri, May 27, 2011 at 9:33 PM, Kevin Trope <[email protected]> wrote: > >> Hello, >> >> >> >> I’m currently trying to write a picture slideshow in QML, where the URLs >> for the images are stored in a QAbstractListModel (with role “imagePath”). >> >> >> >> My approach is to have an Image item and to set the ‘source’ property of >> this Image to a new value when displaying the next, or previous, picture. >> >> But I cannot figure out how to access the data model from a QML item, to >> check that my index is valid and to retrieve the “imagePath” value. >> >> >> >> >> >> Sample from my code: >> >> >> >> FocusScope { >> >> id: slideshowScope >> >> focus: true >> >> >> >> property int currentIndex >> >> property variant model >> >> >> >> signal exitSlideshow() >> >> signal playNext() >> >> signal playPrevious() >> >> >> >> function playImage(newModel, index) { >> >> model = newModel; >> >> console.log("playImage"); >> >> if ((index >= 0) && (index < model.count)) { >> >> slideshowScope.focus = true; >> >> slideshowScope.visible = true; >> >> imageDisplay.source = model[index].imagePath; >> >> currentIndex = index; >> >> } >> >> else { >> >> exitSlideshow(); >> >> } >> >> } >> >> >> >> Image { >> >> id: imageDisplay >> >> width: parent.width; height: parent.height >> >> fillMode: Image.PreserveAspectFit >> >> } >> >> >> >> Timer { >> >> id: slideshowTimer >> >> interval: 5000; running: slideshowScope.visible; >> >> onTriggered: { playNext(); } >> >> } >> >> >> >> onPlayNext: { >> >> slideshowScope.playImage(model,currentIndex+1); >> >> } >> >> >> >> onPlayPrevious: { >> >> slideshowScope.playImage(model,currentIndex-1); >> >> } >> >> } >> >> >> >> >> >> The model is set in another window, where a ListView has the model >> instantiated. >> >> Model.count is undefined here. >> >> >> >> Can someone give me a hand? >> >> >> >> >> >> Cheers, >> >> Kevin >> >> >> >> >> __________ Information from ESET NOD32 Antivirus, version of virus >> signature database 6158 (20110527) __________ >> >> The message was checked by ESET NOD32 Antivirus. >> >> http://www.eset.com >> >> _______________________________________________ >> Qt-qml mailing list >> [email protected] >> http://lists.qt.nokia.com/mailman/listinfo/qt-qml >> >> >
_______________________________________________ Qt-qml mailing list [email protected] http://lists.qt.nokia.com/mailman/listinfo/qt-qml
