Need help using QXmlStreamReader.
Posted: Tue Nov 29 2022 11:02 pm
Hi All!
I have this code that needs to read a bunch of XML files from a hierarch of directories. But when it reachs 1850 files it crashs in what appers to be the destructor of QXmlStreamReader. But I donĀ“t have the expertice in debuging. Does this code has some bug or undefined behavior ?
The files that need to read from have 9 to 19 KB of information, from a total of 4800 files.
I have tested on CopperSpice 1.7.4 and 1.8.0 using MinGW 7.3.0.
Thanks in advance.
I have this code that needs to read a bunch of XML files from a hierarch of directories. But when it reachs 1850 files it crashs in what appers to be the destructor of QXmlStreamReader. But I donĀ“t have the expertice in debuging. Does this code has some bug or undefined behavior ?
The files that need to read from have 9 to 19 KB of information, from a total of 4800 files.
I have tested on CopperSpice 1.7.4 and 1.8.0 using MinGW 7.3.0.
Thanks in advance.
Code: Select all
const QString repositorioXml = "C:\\XML";
QVector<QString> listaDiretorios;
listaDiretorios.push_back(repositorioXml);
int nFile{};
while (!listaDiretorios.isEmpty()) {
QDir dirAtual(listaDiretorios.back());
const auto listaEntradas = dirAtual.entryInfoList({"*.xml"}, QDir::NoDotAndDotDot | QDir::AllDirs | QDir::Files);
for (const auto &info: listaEntradas) {
if (info.isDir()) {
listaDiretorios.push_front(info.absoluteFilePath());
} else if (info.isFile()) {
auto fnLerArquivo = [&]() {
QFile arqXml(info.absoluteFilePath());
if (!arqXml.open(QFile::ReadOnly)) {
spdlog::warn("Falha na abertura do arquivo.");
return false;
}
spdlog::info("{} Arquivo XML: {}.", nFile++, info.absoluteFilePath().toStdString());
QXmlStreamReader leitorXml(&arqXml);
while (!leitorXml.atEnd()) {
leitorXml.readNext();
if (leitorXml.isStartElement()) {
//spdlog::info("{}", leitorXml.name().toString().toStdString());
}
}
return true;
};
if (!fnLerArquivo())
continue;
}
}
listaDiretorios.pop_back();
}