how to pass a model to playlist qml type?
Unsolved
General and Desktop
-
I'm trying to implement a music player using Playlist type but didn't know how to pass my model to it, it's a c++ model that contains the URL's of my music:
static QStringList pathList; …. int main(int argc, char *argv[]){ ….. QDirIterator it("E:/", QStringList() << "*.mp3", QDir::Files, QDirIterator::Subdirectories); while (it.hasNext()){ qDebug() << it.next(); pathList.append(it.next()); } QQmlContext *ctxt1 = engine.rootContext(); ctxt1->setContextProperty("pathModel", QVariant::fromValue(pathList)); //used model pathmodel …. }
and my playlist code on the qml side:
Rectangle{ width: page.width height: page.height Audio { id: player; playlist: Playlist { id: playlist PlaylistItem { source: "song1.ogg"; } //I want this process to be automated instead of doing it manually PlaylistItem { source: "song2.ogg"; } PlaylistItem { source: "song3.ogg"; } } } ListView { model: playlist; delegate: Text { font.pixelSize: 16; text: source; } } MouseArea { anchors.fill: parent; onPressed: { if (player.playbackState != Audio.PlayingState) { player.play(); } else { player.pause(); } } } }
I tried using App list view type but I only managed to play/pause a song on click and couldn't implement functions like autoplay next when a song finishes or stop the current one when another song is selected.