Hi,
I am trying to read configuration with QDomDocument. I managed to get writting configuration to work. When reading I get the settings but don't get any phone numbers.
This is an example of what I might read (there can be between 0 and 999 phone numbers):
<!--Main Settings-->
<settings AfterHourOffset="100" NumPerButton="1" MaxNumToDial="1" />
<!--Phone Book List-->
<phone location="0" value="911" />
<phone location="1" value="33782134" />
<phone location="2" value="000" />
<phone location="3" value="ABCD" />
<phone location="8" value="13005696" />
<phone location="990" value="38441104" />
<phone location="999" value="131333" />
<!--Main Settings-->
<settings AfterHourOffset="100" NumPerButton="1" MaxNumToDial="1" />
<!--Phone Book List-->
<phone location="0" value="911" />
<phone location="1" value="33782134" />
<phone location="2" value="000" />
<phone location="3" value="ABCD" />
<phone location="8" value="13005696" />
<phone location="990" value="38441104" />
<phone location="999" value="131333" />
To copy to clipboard, switch view to plain text mode
Here's my current attempt:
d.setContent(&file);
ClearPhoneNumbers(); // Clear phone table.
while(!n.isNull()) {
if(n.isElement()) {
if(name == "settings") {
ui->Edit1->setText(e.attribute("AfterHourOffset",""));
ui->Edit2->setText(e.attribute("MaxNumToDial",""));
ui->Edit3->setText(e.attribute("NumPerButton",""));
} else if(name == "phone") {
QString location
= e.
attribute("location",
"");
QString value
= e.
attribute("value",
"");
AddPhoneBook(location, value); // Add to phone table.
}
}
n = n.nextSibling();
}
file.close();
}
QFile file("fred.xml");
if(file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QDomDocument d;
d.setContent(&file);
QDomNode n = d.firstChild();
ClearPhoneNumbers(); // Clear phone table.
while(!n.isNull()) {
if(n.isElement()) {
QDomElement e = n.toElement();
QString name = e.tagName();
if(name == "settings") {
ui->Edit1->setText(e.attribute("AfterHourOffset",""));
ui->Edit2->setText(e.attribute("MaxNumToDial",""));
ui->Edit3->setText(e.attribute("NumPerButton",""));
} else if(name == "phone") {
QString location = e.attribute("location","");
QString value = e.attribute("value","");
AddPhoneBook(location, value); // Add to phone table.
}
}
n = n.nextSibling();
}
file.close();
}
To copy to clipboard, switch view to plain text mode
See whats wrong?
Thanks
Brendan
Bookmarks