Important: Please read the Qt Code of Conduct -

Failing to SetFilter of QFileSystemModel for .mp3/.avi files

  • I need to traverse my drives in system and display only .mp3 and .avi files. basically set the filter to these extensions and display the files in a treeview.

    @QStringList sDriveFilters;
    QString sPath = m_SystemModel->fileInfo(index).absoluteFilePath();

    sDriveFilters << "*.aac" << "*.wmv" << "*.avi" << "*.mpeg" << "*.mov" << "*.3gp" << "*.flv" << "*.mp3" ;
    m_SystemModel->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs );
    m_SystemListViewModel->setFilter( QDir::Files | QDir::AllDirs | QDir::NoDotAndDotDot );

    If you notice I have set filter as @setFilter( QDir::Files | QDir::AllDirs | QDir::NoDotAndDotDot )@

    and setNameFilters to sDriveFilters. This displays all the directories in my treeview. Ideally I want it to display only audio/video files.

Log in to reply