Reputation: 824
I have a QFileInfoList (list) that contains info about a directory and its file
QFileInfoList list = directory.entryInfoList();
How can I apply filters to remove everything except image file(jpg, gif, png etc.) ?
Here is a simple foreach loop that only removes everything that is not a file
foreach (QFileInfo f, list){
if (!f.isFile()){
list.removeOne(f);
}
How can I apply filters to remove everything except image file(jpg, gif, png etc.) ?
Upvotes: 8
Views: 18722
Reputation: 1189
QDir::entryInfoList() takes name filters, if you're comfortable determining images by extension:
QStringList nameFilter;
nameFilter << "*.png" << "*.jpg" << "*.gif";
QFileInfoList list = directory.entryInfoList( nameFilter, QDir::Files );
Upvotes: 19
Reputation: 13130
First of all, why won't you use proper flags to QDir::entryInfoList and filter out everything that is not a directory, and desired file extensions.
Secondly, you may use on each file `bool QImageReader::canRead(, but it will access files to check if they're images, so it will be quite slow.
Also you may try to build up supported extensions with QImageReader::supportedImageFormats ()
, and add them as filter to entryInfoList
Upvotes: 2