I try to parse an XML File with my programme cpp, and to stock it on a QList, but i dont know why when i execute the code the application return nothing ( and sometimes it close alone )
this is my function :
void mission::loadMission(QList < waypoint* > wpList , QString filename){
QXmlStreamReader xmlReader;
int i=0 ;
QFile file(filename);
if(file.open(QIODevice::ReadOnly)) {
xmlReader.setDevice(&file);;
xmlReader.readNext();
xmlReader.readNext();
bool ok = false ;
//Reading from the file
while (!xmlReader.isEndDocument())
{
if (xmlReader.isStartElement())
{
QString name = xmlReader.name().toString();
if (name == "Number" )
{
wpList[i]->setNum(xmlReader.readElementText().toInt(&ok,10));
}
else if (name == "Longitude" )
{
wpList[i]->setLong(xmlReader.readElementText().toDouble(&ok));
}
else if (name == "Latitude" )
{
wpList[i]->setLat(xmlReader.readElementText().toDouble(&ok));
}
else if (name == "Altitude" )
{
wpList[i]->setAlt(xmlReader.readElementText().toDouble(&ok));
}
else if (name == "Heading" )
{
wpList[i]->setHdg(xmlReader.readElementText().toDouble(&ok));
}
else if (name == "Time" )
{
wpList[i]->setTime(xmlReader.readElementText().toInt(&ok,10));
}
else if (name == "Type" )
{
wpList[i]->setType(xmlReader.readElementText().toInt(&ok,10));
}
}
else if (xmlReader.isEndElement())
{
xmlReader.readNext();
i++ ;
}
}
if (xmlReader.hasError())
{
cout << "XML error: " << xmlReader.errorString().data() << std::endl;
}
}
}
and this an exemple for my XML file :
<?xml version="1.0" encoding="UTF-8"?>
<Mission>
<Number>2013_7_11_16_28</Number>
<Waypoint>
<Number>0</Number>
<Longitude>1.26946</Longitude>
<Latitude>43.5147</Latitude>
<Altitude>100</Altitude>
<Heading>90</Heading>
<Time>4400</Time>
<Type>1</Type>
</Waypoint>
<Waypoint>
<Number>1</Number>
<Longitude>1.56958</Longitude>
<Latitude>43.4721</Latitude>
<Altitude>100</Altitude>
<Heading>90</Heading>
<Time>4400</Time>
<Type>1</Type>
</Waypoint>
<Waypoint>
<Number>2</Number>
<Longitude>1.64424</Longitude>
<Latitude>43.655</Latitude>
<Altitude>100</Altitude>
<Heading>90</Heading>
<Time>4400</Time>
<Type>1</Type>
</Waypoint>
</Mission>