PDA

View Full Version : How to set filter of QFileSystemModel to display only audio and video files



owais_blore
20th November 2012, 10:05
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

// Gets called when application starts
void DetailView::onCamStartup()
{
m_SystemModel = new QFileSystemModel(this);
m_SystemListViewModel = new QFileSystemModel(this);
m_SystemModel->setRootPath(QDir::currentPath());
ui->DriveView->setModel(m_SystemModel);
ui->DriveListView->setModel(m_SystemListViewModel);

// regard less how many columns you can do this using for:
for(int nCount = 1; nCount < m_SystemModel->columnCount(); nCount++)
ui->DriveView->hideColumn(nCount);
}

// Displays Files in Detail View on Clicking Drive
void DetailView::on_DriveView_clicked(const QModelIndex &index)
{
QStringList sDriveFilters;
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 );

sDriveFilters << "*.aac" << "*.wmv" << "*.avi" << "*.mpeg" << "*.mov" << "*.3gp" << "*.flv" << "*.mp3" ;
m_SystemListViewModel->setNameFilters(sDriveFilters);
m_SystemListViewModel->setNameFilterDisables(false);
}

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:
8441
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?