Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to pass a model to playlist qml type?
QtWS25 Last Chance

how to pass a model to playlist qml type?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qmlmultimediaaudioaudio qmlitem delegate
1 Posts 1 Posters 430 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    newbiSoso
    wrote on last edited by newbiSoso
    #1

    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.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved