Pergunta

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?

Foi útil?

Solução

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.

Outras dicas

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" );
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top