Page 1 of 1

Need help using QXmlStreamReader.

Posted: Tue Nov 29 2022 11:02 pm
by FullAlquimista
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.

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();
  }
  

Re: Need help using QXmlStreamReader.

Posted: Fri Dec 09 2022 3:24 am
by barbara
Can you post the error report. If it is really long then email it to us info @ copperspice.com

Thanks.

Re: Need help using QXmlStreamReader.

Posted: Fri Dec 09 2022 8:06 am
by FullAlquimista
Hi!

I sent the email with two screenshots of the issue in debug mode.

Re: Need help using QXmlStreamReader.

Posted: Tue Dec 13 2022 1:00 am
by ansel
Can you try a couple different variations of your code?
  • If you process the first 1000 files twice, does it still crash?
  • If you remove the last 2 or 3 files it processed from the directory, can it process the rest of the files?
  • If you process the files in reverse order, what happens?

Re: Need help using QXmlStreamReader.

Posted: Wed Dec 21 2022 2:04 am
by FullAlquimista
Can you try a couple different variations of your code?

If you process the first 1000 files twice, does it still crash?
No, it pass throught. But crashes using other directories with less than a half of files.
If you remove the last 2 or 3 files it processed from the directory, can it process the rest of the files?
No. It crash in the next file.
If you process the files in reverse order, what happens?
If I remove some files, it changes the number of files that can process without crashing.

I Will send you the files so that you can test and see.

Re: Need help using QXmlStreamReader.

Posted: Thu Dec 22 2022 12:03 pm
by FullAlquimista
I have sended the files via WeTransfer to info@copperspice.com

Re: Need help using QXmlStreamReader.

Posted: Mon Dec 26 2022 3:58 am
by barbara
Can you resend the link to the files.

Thanks,

Barbara

Re: Need help using QXmlStreamReader.

Posted: Tue Dec 27 2022 12:15 am
by FullAlquimista
I resend the files.

Thank you.

Re: Need help using QXmlStreamReader.

Posted: Wed Dec 28 2022 6:12 pm
by barbara
Thanks, have the files now and someone on the team will take a look at this.