how to save and load playlist in qt ?



  • hello , i am new to qt and i am making a mp3 player but i am getting a problem in saving and loading playlist . can anyone please tell a easy code to save and load playlist in qt.



  • Open file containing playlist with QFile and then read/write it with QTextStream or QDataStream. Smth like this:

    // Reading
    QFile f("list.pl");
    if (f.open(QFile::ReadOnly)) {
      QDataStream s(&f);
      QString song;
      while (!s.atEnd()) { s >> song; }
    }
    

    You can extend QDataStream for reading/writing your custom data (http://doc.qt.io/qt-5/qdatastream.html)


  • Qt Champions 2017

    #include <QMediaPlaylist>
    #include <QFileDialog>
    #include <QDebug>
    void MainWindow::on_pushButton_released()
    {
    QMediaPlaylist* playlist = new QMediaPlaylist;
    playlist->addMedia(QUrl("http://example.com/movie1.mp4"));
    playlist->addMedia(QUrl("http://example.com/movie2.mp4"));
    playlist->addMedia(QUrl("http://example.com/movie3.mp4"));
    QString fn=QFileDialog::getSaveFileName(this,"Save file",QDir::currentPath(),
    "Text files (.txt);;All files (.*)");
    qDebug() << playlist->save(QUrl::fromLocalFile(fn),"m3u");
    delete QMediaPlaylist;
    }


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.