Need help using QXmlStreamReader.

Post Reply
FullAlquimista
Posts: 10
Joined: Sun Jan 10 2021 11:24 pm

Need help using QXmlStreamReader.

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

barbara
Posts: 380
Joined: Sat Apr 04 2015 2:32 am
Contact:

Re: Need help using QXmlStreamReader.

Post by barbara »

Can you post the error report. If it is really long then email it to us info @ copperspice.com

Thanks.

FullAlquimista
Posts: 10
Joined: Sun Jan 10 2021 11:24 pm

Re: Need help using QXmlStreamReader.

Post by FullAlquimista »

Hi!

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

ansel
Posts: 139
Joined: Fri Apr 10 2015 8:23 am

Re: Need help using QXmlStreamReader.

Post 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?
Ansel Sermersheim
CopperSpice Cofounder

FullAlquimista
Posts: 10
Joined: Sun Jan 10 2021 11:24 pm

Re: Need help using QXmlStreamReader.

Post 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.

FullAlquimista
Posts: 10
Joined: Sun Jan 10 2021 11:24 pm

Re: Need help using QXmlStreamReader.

Post by FullAlquimista »

I have sended the files via WeTransfer to info@copperspice.com

barbara
Posts: 380
Joined: Sat Apr 04 2015 2:32 am
Contact:

Re: Need help using QXmlStreamReader.

Post by barbara »

Can you resend the link to the files.

Thanks,

Barbara

FullAlquimista
Posts: 10
Joined: Sun Jan 10 2021 11:24 pm

Re: Need help using QXmlStreamReader.

Post by FullAlquimista »

I resend the files.

Thank you.

barbara
Posts: 380
Joined: Sat Apr 04 2015 2:32 am
Contact:

Re: Need help using QXmlStreamReader.

Post by barbara »

Thanks, have the files now and someone on the team will take a look at this.

Post Reply