Hi,
I got a little further. Using the tutorial I got the code so far that it reads the xml file. My problem is now to get the data into my custom class and then into a vector. The tutorial uses if statements to determent where the information should go. With two elements thats okay but I got more than 40 and that is just not very handy. Here is the code snippet where the data needs to be transferred:
/* If it's named card, we'll dig the information from there.*/
if(xml.name() == "card") {
xml.readNext();
Card card;
while(!(xml.tokenType() == QXmlStreamReader::EndElement && xml.name() == "card")) {
if(xml.tokenType() == QXmlStreamReader::StartElement) {
QString elementName
= xml.
name().
toString();
xml.readNext();
qDebug()<< elementName << "->" << xml.text().toString();
}
/* ...and next... */
xml.readNext();
}
cardData.append(card);
}
/* If it's named card, we'll dig the information from there.*/
if(xml.name() == "card") {
xml.readNext();
Card card;
while(!(xml.tokenType() == QXmlStreamReader::EndElement && xml.name() == "card")) {
if(xml.tokenType() == QXmlStreamReader::StartElement) {
QString elementName = xml.name().toString();
xml.readNext();
qDebug()<< elementName << "->" << xml.text().toString();
}
/* ...and next... */
xml.readNext();
}
cardData.append(card);
}
To copy to clipboard, switch view to plain text mode
In php card would be an associative array and I would fill it $card[elementName] = xml.text().toString(); can I do something similar in Qt? By the way, card is not defined yet. I was not sure how this class should look like so that I can store the information.
Bookmarks