Wednesday, June 30, 2010

Get list of XML files from specified directory. QStringList,QDir,QRegExp

QStringList can be used to store the list of names of xml files which are in a directory. Following method returns the list of names of files matching the regular expression.
QStringList XMLReader::getListOfFiltersFromDirectory()
{
    QDir directory = QDir("C:\\filters");
    QStringList listOfFilters = directory.entryList(QDir::Files | QDir::NoSymLinks);
    QRegExp rx("*.xml");
    rx.setPatternSyntax(QRegExp::Wildcard);
    listOfFilters = listOfFilters.filter(rx);
    return listOfFilters;
}

No comments:

Post a Comment