我想遍历系统中存在的驱动器并搜索其中的音频/视频文件。基本上遍历子目录并在树视图中显示文件。我有 2 个树视图,一个用于显示系统目录,另一个用于显示音频/视频文件。
// Displays System Drives inside TreeView(Drive View) When Application Starts
void PanasonicViewer::onCamStartup()
{
m_SystemModel = new QFileSystemModel(this);
m_SystemListViewModel = new QFileSystemModel(this);
m_SystemModel->setRootPath(QDir::currentPath());
ui->DriveView->setModel(m_SystemModel); //Left side TreeView
ui->DriveListView->setModel(m_SystemListViewModel); //Right Side TreeView
// regard less how many columns you can do this using for:
for(int nCount = 1; nCount < m_SystemModel->columnCount(); nCount++)
ui->DriveView->hideColumn(nCount);
}
//On Clicking The TreeView, it should display Audio and Video files in DriveListView
void PanasonicViewer::on_DriveView_clicked(const QModelIndex &index)
{
QStringList sDriveFilters;
QString sPath = m_SystemModel->fileInfo(index).absoluteFilePath();
ui->DriveListView->setRootIndex(m_SystemListViewModel->setRootPath(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);
}
您可以在上面的单击事件中注意到我已将过滤器设置为选定的扩展。当我单击驱动器即 E:\ 但不显示子文件夹中存在的文件时,这似乎可以工作并显示音频和视频文件。我哪里错了?