You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Thursday, November 22nd 2012, 11:39am

How to display Details of Audio File in QTreeView

I need to display details of all .mp3 files present in my drives. I am using QTreeView to display. Here is the code:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Displays Files in Detail View on Clicking Drive
void DetailView::on_DriveView_clicked(const QModelIndex &index)
{
   int m_count=0;
   QStandardItemModel *model = new QStandardItemModel(0,0);
   QString sPath = m_SystemModel->fileInfo(index).absoluteFilePath();
   m_SystemListViewModel->setRootPath(sPath);
   ui->DriveListView->setRootIndex(m_SystemListViewModel->index(sPath));

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

   QStringList m_list;
   QDirIterator dirIt(sPath,QDirIterator::Subdirectories);

   while (dirIt.hasNext())
   {
      dirIt.next();
      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);

               ui->DriveListView->setModel(model);
               m_count++;
          }
      }
      m_SystemListViewModel->setNameFilterDisables(false);
   }
}

Even though I have used setHeaderData for Size, Type and Date Modified…. it doesnt 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. here is the sample pic:
Please help
owais_blore has attached the following file:
  • File.JPG (17.39 kB - 6 times downloaded - latest: Dec 2nd 2012, 2:43am)