PDA

View Full Version : Read all files in directory



issima90
19th March 2014, 20:03
Hi,
I'm learning to use Qt.
I have to read all XML file existing in a directory.
The code I wrote works well with a single file, but I would have results about all the directory.

Could you suggest me the code that I'd have to paste in my .cpp file that allow me to open a QDialog with the choice of the directory and to select a file per time to read?
Now that piece of code is:


bool DomParser::readFile()
{
QString fileName =
QFileDialog::getOpenFileName(this, tr("Open Gate File"),
QDir::currentPath(),
tr("XML Files (*.xml)"));*/
qDebug() << fileName;
if (fileName.isEmpty())
return false;

QFile file(fileName);
if (!file.open(QFile::ReadOnly | QFile::Text)) {
QMessageBox::warning(this, tr("SAX Bookmarks"),
tr("Cannot read file %1:\n%2.")
.arg(fileName)
.arg(file.errorString()));
return false;
}
qDebug() << "file opened"; ....

This, as I explained, allow me to choose the file and read it. Relevant information will be write into another file so I need all info from all files.
Thank to all.
Please help me!

ChrisW67
19th March 2014, 21:00
QDir particularly QDir::entryList() and a loop

issima90
19th March 2014, 23:08
QDir particularly QDir::entryList() and a loop

Thanks for your answer.
But, how could I write the code?