简体   繁体   English

在QTreeView + QFileSystemModel上循环浏览所有具有所需文件扩展名的项目

[英]Loop through all items with desired file extension on QTreeView + QFileSystemModel

I'm completely newbie to Qt and C++, so I guess this is a very basic question, but I couldn't find it anywhere! 我对Qt和C ++完全是新手,所以我想这是一个非常基本的问题,但是我在任何地方都找不到!

I'm using a QTreeView together with a QFileSystemModel to show the contents of a folder. 我正在使用QTreeView和QFileSystemModel来显示文件夹的内容。 When I need to loop though all selected items on it, I just use: 当我需要遍历所有选定项时,只需使用:

foreach (QModelIndex index, treeView->selectionModel()->selectedRows()) 
{
    //...
}

My question is: 我的问题是:

Is there a similar way to loop through all items with desired file extension (for instance, *.aaa files)? 有没有类似的方法可以循环浏览具有所需文件扩展名的所有项目(例如* .aaa文件)? If it can't be done exactly like this, please tell me how! 如果无法完全按照这种方式进行操作,请告诉我如何!

Edit: Just to make it clear, I'd want to loop through ALL files with given extension, not only the selected ones 编辑:为了清楚起见,我想遍历具有给定扩展名的所有文件,而不仅仅是选定的文件

Thanks in advance! 提前致谢!

Using rowCount, columnCount and hasChildren, one should be able to run over all the elements of an QAbstractItemModel. 使用rowCount,columnCount和hasChildren,应该可以在QAbstractItemModel的所有元素上运行。 Does it help you? 它对你有帮助吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM