XML : Reading XML with QXmlStreamReader gives ASSERT failure in QVector

I have such XML file:

  <?xml version="1.0" encoding="UTF-8"?>  <OrderDetails>      <Companies number_of_companies="2" number_of_tasks="3">          <Company id="1">              <Tasks>                  <Task id="1" brutto="0" netto="0" euro="0"/>                  <Task id="2" brutto="0" netto="0" euro="0"/>                  <Task id="3" brutto="0" netto="0" euro="0"/>              </Tasks>          </Company>          <Company id="2">              <Tasks>                  <Task id="1" brutto="0" netto="0" euro="0"/>                  <Task id="2" brutto="0" netto="0" euro="0"/>                  <Task id="3" brutto="0" netto="0" euro="0"/>              </Tasks>          </Company>      </Companies>  </OrderDetails>    

I need to store brutto (netto, euro) prices in a QVector<QVector<double> >, but with the below code:

  QVector<QVector<double> > getBrutto(QString xml)  {      QXmlStreamReader xmlReader(xml);        int companies = getNumOfCompanies(xml);      int tasks = getNumOfTasks(xml);        QVector<QVector<double> > bruttoCosts;      int i=0, j = 0;        while(!xmlReader.atEnd() && !xmlReader.hasError()){          QXmlStreamReader::TokenType token = xmlReader.readNext();          if (xmlReader.name() == "Task" && xmlReader.isStartElement() && !xmlReader.isWhitespace())          {              bruttoCosts[i].append(xmlReader.attributes().value("brutto").toDouble());                i ++;              if(i == companies)                  i = 0;          }      }        return bruttoCosts;  }    

I got the error: ASSERT failure in QVector<T>::operator[]: "index out of range". As you can see from the above code, I successfully obtained number of companies (getNumOfCompanies(xml);) and tasks (getNumOfTasks(xml);), but somehow have problems with parsing brutto values.

No comments:

Post a Comment