Tour Preview

Find the Best Demos and Examples

Check out this quick tour to find the best demos and examples for you, and to see how the Felgo SDK can help you to develop your next app or game!

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.