I am using QFileSystemModel for exploring my drive and QSortFilterProxyModel for filtering all the files and folders in it. It works well when i try to display the model in a QTreeview. Now my problem is, when i try to get all the files and folders names in a list. It gives me unfiltered names. I am using this:


Qt Code:
  1. QFileSystemModel *fileSystemModel;
  2. fileSystemModel = new QFileSystemModel(this);
  3. QSortFilterProxyModel proxyModel = new QSortFilterProxyModel(targetDir);
  4. QModelIndex rootModelIndex = fileSystemModel->setRootPath(path);
  5. QStringList filters;
  6. filters <<"*.jpeg" <<"*.pict" ;
  7. fileSystemModel->setNameFilters(filters);
  8. fileSystemModel->setNameFilterDisables(0);
  9. proxyModel->setSourceModel(fileSystemModel);
  10. fileSystemModel->fetchMore(rootModelIndex);
  11. fileSystemModel->sort(0,Qt::AscendingOrder);
  12. ui->treeView_2->setModel(proxyModel);
  13. ui->treeView_2->setRootIndex(proxyModel->mapFromSource(rootModelIndex));
  14. connect(fileSystemModel,SIGNAL(directoryLoaded(QString)),this,SLOT(onDirLoaded(QString)));
  15.  
  16. for names list i am using the Directoryloaded() signal of QFileSystemModel:
  17.  
  18. void MainWindow::onDirLoaded(QString path)
  19. {
  20. QModelIndex index = fileSystemModel->index(path);
  21. int rowCount = fileSystemModel->rowCount(index);
  22. for(int i=0;i<rowCount;i++)
  23. {
  24. QModelIndex mi = fileSystemModel->index(i,0,index);
  25.  
  26. QFileInfo fileInfo = fileSystemModel->fileInfo(mi);
  27. if (!templist.contains(fileInfo.absoluteFilePath()))
  28. {
  29. templist << fileInfo.absoluteFilePath();
  30. tempNamelist << fileInfo.fileName();
  31. }
  32. if(!bloaded)
  33. {
  34. if(fileSystemModel->hasChildren(mi))
  35. {
  36. QModelIndex index1 = fileSystemModel->index(i,0,index);
  37. int rowCount1 = fileSystemModel->rowCount(index1);
  38. if(rowCount1)
  39. {
  40. onDirLoaded(fileInfo.absoluteFilePath());
  41. }
  42. }
  43. }
  44. }
  45. }
To copy to clipboard, switch view to plain text mode 

After this i am getting list of all the files and folders but its unfiltered names.I want filtered names. Is there anyone who can help me in this ? Your help will really appreciate guys.
Thanks.