Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter QFileInfoList files with Qt

Tags:

c++

qt

qt4

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.) ?

like image 394
Sharethefun Avatar asked Dec 06 '10 08:12

Sharethefun


1 Answers

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 );
like image 175
Scott Avatar answered Sep 25 '22 13:09

Scott