I want to traverse the drives present in my system and search for audio/video files inside it. Basically I need to traverse my drives and display only .mp3 and .avi files. Then set the filter to these extensions and display the files in a treeview. I have 2 tree views, One to display System Directories and other to display audio/video files
Qt Code:
  1. // Gets called when application starts
  2. void DetailView::onCamStartup()
  3. {
  4. m_SystemModel = new QFileSystemModel(this);
  5. m_SystemListViewModel = new QFileSystemModel(this);
  6. m_SystemModel->setRootPath(QDir::currentPath());
  7. ui->DriveView->setModel(m_SystemModel);
  8. ui->DriveListView->setModel(m_SystemListViewModel);
  10. // regard less how many columns you can do this using for:
  11. for(int nCount = 1; nCount < m_SystemModel->columnCount(); nCount++)
  12. ui->DriveView->hideColumn(nCount);
  13. }
  15. // Displays Files in Detail View on Clicking Drive
  16. void DetailView::on_DriveView_clicked(const QModelIndex &index)
  17. {
  18. QStringList sDriveFilters;
  19. QString sPath = m_SystemModel->fileInfo(index).absoluteFilePath();
  20. m_SystemListViewModel->setRootPath(sPath);
  21. ui->DriveListView->setRootIndex(m_SystemListViewModel->index(sPath));
  23. m_SystemModel->setRootPath(QDir::currentPath());
  24. m_SystemModel->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs );
  25. m_SystemListViewModel->setFilter( QDir::Files | QDir::NoDotAndDotDot );
  27. sDriveFilters << "*.aac" << "*.wmv" << "*.avi" << "*.mpeg" << "*.mov" << "*.3gp" << "*.flv" << "*.mp3" ;
  28. m_SystemListViewModel->setNameFilters(sDriveFilters);
  29. m_SystemListViewModel->setNameFilterDisables(false);
  30. }
To copy to clipboard, switch view to plain text mode 

You can notice in the above click event that I have set Filter to selected extensions. It displays the mp3 files which are in the drive but it doesnt parse the subfolders and fails to display the audio/video files present inside it.

Here is the image:
If you notice there are Folders inside SONGS folder where mp3 files are present but it doesnt display at all. Basically if i click New Volume E: it should display all mp3/.avi files in my right side treeview. Now i clicked SONGS folder, it displays one file inside the folder but it doesnt display the files inside the subfolders present. Where am i making mistake?