Domanda

setNameFilters isn't working as I would expect, so if anyone can explain if I'm using it incorrectly, or if maybe this is a bug in Qt:

Here is my code sample:

QDir export_folder("C:\path");
QStringList fileList = export_folder.setNameFilters(QStringList()<<"*.exe");

after processing fileList contains the String "test.exe1"

I would expect fileList to only include files with extension .exe NOT .exe*.

If I wanted file extensions longer than .exe I would expect to put in "*.exe*" as my filter.

Can someone help clarify, or do I manually have to process my fileList after the fact?

È stato utile?

Soluzione

For starters, setNameFilters does not return QStringList, it returns nothing. Your code should look like this:

QDir export_folder("C:\\path");
export_folder.setNameFilters(QStringList()<<"*.exe");
QStringList fileList = export_folder.entryList();

Filtering works as expected (not returning files ending with "exe2") in Linux with Qt 5.0.1.

Altri suggerimenti

Also, if you want to show files with more than one kind of extensions, you can do like the following.

export_folder.setNameFilters( QStringList() << "*.exe" << "*.pdf" << "*.docx" << "*.jpg" );
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top