Forums

OverviewFelgo 2 Support (Qt 5) › how do I pass a model to Playlist QML type?

Tagged: 

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #21727

    sAMA SAMA

    I have this rectangle to implement a playlist:

    Rectangle{
                    width: page.width
                    height: page.height
                    Audio {
                           id: player;
                           playlist: Playlist {
                               id: playlist
                               PlaylistItem { source: "E:/Breaeze/SampleAudio_0.4mb.mp3"; }
                               PlaylistItem { source: "E:/crowd-cheering1.mp3"; }
                               PlaylistItem { source: "E:/Felgo/Examples/Felgo/demos/CrazyCarousel/assets/sound/Carousel.mp3"; }
                           }
                       }
    
                       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 have a c++ model contains all the music URLs & want to use it instead of adding every song manually to the playlist, this is my c++ model implementation:

    static QStringList pathList; //to save the URLs
    
    ….
    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
    
    ….
    }
    

    but I cant pass it as a model what can I do?

Viewing 1 post (of 1 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support