Answer the question
In order to leave comments, you need to log in
Why doesn't XmlReader work in QT?
Hello. I am making a simple xml file parser in qt, but the code does not go further than the line if(xmlReader.isStartElement())
. The debugger at the breakpoint does not move further through the code. Here is the code in full:
class Maket{
public:
QString name;
QString timeBegin;
QString timeCancel;
int statValue;
};
QFile file("maket.xml");
QList<Maket> maketList;
if(file.open(QIODevice::ReadOnly)){
QXmlStreamReader xmlReader;
xmlReader.setDevice(&file);
xmlReader.readNext();
while (!xmlReader.atEnd()) {
if(xmlReader.isStartElement()){
Maket maket;
if(xmlReader.name() == "measuringpoint"){
foreach (const QXmlStreamAttribute& attr, xmlReader.attributes()) {
if(attr.name().toString() == "name"){
maket.name = attr.value().toString();
}
}
}
else if(xmlReader.name() == "period"){
foreach (const QXmlStreamAttribute& attr, xmlReader.attributes()) {
if(attr.name().toString() == "start"){
maket.timeBegin = attr.value().toString();
}
}
}
else if(xmlReader.name() == "period"){
foreach (const QXmlStreamAttribute& attr, xmlReader.attributes()) {
if(attr.name().toString() == "end"){
maket.timeCancel = attr.value().toString();
}
}
}
else if(xmlReader.name() == "value"){
foreach (const QXmlStreamAttribute& attr, xmlReader.attributes()) {
if(attr.name().toString() == "value"){
maket.statValue = attr.value().toInt();
}
}
}
maketList.push_back(maket);
xmlReader.readNext();
}
file.close();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question