Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved how to save and load playlist in qt ?

    General and Desktop
    3
    3
    1685
    Loading More Posts
    • 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.
    • S
      smart.dhariwal last edited by smart.dhariwal

      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.

      1 Reply Last reply Reply Quote 0
      • G
        Gres last edited by

        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)

        1 Reply Last reply Reply Quote 0
        • mrjj
          mrjj Lifetime Qt Champion last edited by

          #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;
          }

          1 Reply Last reply Reply Quote 0
          • First post
            Last post