Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to save and load playlist in qt ?
QtWS25 Last Chance

how to save and load playlist in qt ?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 1.9k Views
  • 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 Offline
    S Offline
    smart.dhariwal
    wrote on last edited by smart.dhariwal
    #1

    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
    0
    • G Offline
      G Offline
      Gres
      wrote on last edited by
      #2

      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
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        #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
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved