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("");
    if ( {
      QDataStream s(&f);
      QString song;
      while (!s.atEnd()) { s >> song; }

    You can extend QDataStream for reading/writing your custom data (

  • Qt Champions 2017

    #include <QMediaPlaylist>
    #include <QFileDialog>
    #include <QDebug>
    void MainWindow::on_pushButton_released()
    QMediaPlaylist* playlist = new QMediaPlaylist;
    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.