Important: Please read the Qt Code of Conduct -

Cannot get metadata from audio file while loading it

  • Hi everyone,

    I have a problem getting metadata from file while loading it from disk. I can play it etc. but can't get metadata while loading it.

    Here is my loading function:
    Btw. the "ui->playlistView" element is QTableWidget.
    @void MainWindow::on_actionOpen_triggered()
    QFileDialog *fileDialog = new QFileDialog(this);
    QStringList selectedFiles;

    selectedFiles = fileDialog->getOpenFileNames(this, "Select songs", QDir::homePath(), "mp3 files (*.mp3)");
        ui->playlistView->setHorizontalHeaderItem(0, new QTableWidgetItem("Title"));
        ui->playlistView->setHorizontalHeaderItem(1, new QTableWidgetItem("Artist"));
        ui->playlistView->setHorizontalHeaderItem(2, new QTableWidgetItem("Album"));
        for(int i = 0; i < selectedFiles.count(); i++){
            ui->playlistView->setItem(i, 0, new QTableWidgetItem(player->metaData("").toString()));
            ui->playlistView->setItem(i, 1, new QTableWidgetItem(player->metaData("").toString()));
            ui->playlistView->setItem(i, 2, new QTableWidgetItem(player->metaData("AlbumTitle").toString()));


    Thanks for help. :)

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You should add which version of Qt you are using as well as the OS you are running on

  • Hi,

    I'm running Qt 5.2.1 (GCC 4.8.2, 64 bit) on Ubuntu 14.04. I can get the metadata for one song, but I want to list throught all loaded files and load their metadata while loading them from disk. Is there a way how to achieve it? I'm using QMediaPlayer and QMediaPlaylist for handling media and QTableWidget to display songs info in table. But I cannot get their metadata while loading them...

    Any help will be appreciated. :)

  • cmoud94, I am in the same predicament as you. It seems as though in Qt that it can only retrieve the metadata of a media file while it is playing. So in my code I have a play button that plays the current song in a playlist and gets the metadata as well. The first time I click the button it returns empty strings, but the second time I click the play button it gets the correct metadata. So I think I might have to use taglib for my metadata needs. @void MainWindow::playButtonclicked(){

    if (player->isMetaDataAvailable())
      qDebug() << "there is metadata";
      qDebug() << "No metadata.";
    QVariant songTitle = player->metaData(QMediaMetaData::Title);
    QString songTitleString = songTitle.toString();

    I have also found that with my if statement, the first time I click the button it will print out 'No metadata." but the second time it will print 'there is metadata'. So now I am stuck.

  • Kinexd, I can get the metadata while I'm playing song or if I list through the playlist while it's loaded (with "Next Song" button). But if I try to list the playlist after it's loaded it does not work...

Log in to reply