Display Audio File Attributes in QTreeView

  • Well I need to display details of all .mp3 files present in my system drives. I am using QTreeView which gives me File Name, Size, Type and Date Modified by default to display. Here is the sample code:
    @void DetailView::on_DriveView_clicked(const QModelIndex &index)
    int m_count=0;
    QStringList m_list;
    QStandardItemModel *model = new QStandardItemModel(0,0);
    QString sPath = m_SystemModel->fileInfo(index).absoluteFilePath();

    m_SystemModel->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs );
    m_SystemListViewModel->setFilter( QDir::Files | QDir::NoDotAndDotDot );

    QDirIterator dirIt(sPath,QDirIterator::Subdirectories);

    while (dirIt.hasNext())
    if (QFileInfo(dirIt.filePath()).isFile())
    if (QFileInfo(dirIt.filePath()).suffix() == "mp3")
    m_list << dirIt.filePath();

               QModelIndex index = model->index(m_count, 0, QModelIndex());
               model->setHeaderData( 0, Qt::Horizontal, "File Name" );
               model->setHeaderData( 1, Qt::Horizontal, "Size" );
               model->setHeaderData( 2, Qt::Horizontal, "Type" );
               model->setHeaderData( 3, Qt::Horizontal, "Date Modified" );
               model->setData( index, dirIt.fileName(), Qt::DecorationRole );
               QStandardItem *item = new QStandardItem(dirIt.fileName());
               model->setItem(m_count, item);


    When I run the app, Have a look at my code, even though I have used setHeaderData for Size, Type and Date Modified, it gets displayed when I run the application but the moment i click any system drive, only File Name appears and rest doesn't get displayed. I am using QTreeView, as of now my code displays all the .mp3 files under Name category. I want to display the Size, Date Modified, Type etc details too.

Log in to reply

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