PDA

View Full Version : Is there any example code which read and writes data from/to XML file?



rajesh
23rd June 2006, 07:14
Is there any example code which read and writes data from/to XML file?

munna
23rd June 2006, 07:23
Qt examples contains an example that reads and write xml file. I think it is called dombookmarks.

nupul
23rd June 2006, 09:21
Is there any example code which read and writes data from/to XML file?


Yes! just launch Qt Demo (Qt 4) and the select the bottom most option "XML"!!!

patrik08
23rd June 2006, 18:46
Is there any example code which read and writes data from/to XML file?

This follow line source fill 14 qlineedit & 5 qcombobox on method:

http://doc.trolltech.com/4.1/qobject.html#findChildren

is the application setting file .....

and inverse / write you can found on http://qtforum.de/forum/viewtopic.php?t=2192




void Setting_Gui::ReadConfig()
{
QString configwget = APPLICATION_SETTING;
QFile xmlfile(configwget);
if(!xmlfile.open( QIODevice::ReadOnly ) ) {
ErrorConfig("");
}
QString errorStr, obname, inhalt;
int errorLine;
int errorColumn;

QDomDocument doc("http://www.pulitzer.ch/2005/PuliCMS/1.0");
if (!doc.setContent(&xmlfile,true, &errorStr, &errorLine, &errorColumn)) {
QString error = (QString("Parse error at line %1, column %2:\n%3")
.arg(errorLine)
.arg(errorColumn)
.arg(errorStr) );
ErrorConfig(error);
xmlfile.close();
}
QDomElement root = doc.documentElement();
if( root.tagName() != "setting" ) {
ErrorConfig("");
}
QDomNode n = root.firstChild();
while( !n.isNull() )
{
QDomElement e = n.toElement();
if( !e.isNull() )
{
for (int i=0;i<textList.size();i++){
obname =QString(textList[i]->objectName());
if( e.tagName() == obname ) {
textList[i]->setText(decodeBase64(e.text()));
}
}
for (int x=0;x<boxList.size();x++){
obname =QString(boxList[x]->objectName());
if( e.tagName() == obname ) {
inhalt = decodeBase64(e.text());
int summ = boxList[x]->count();
for (int i=0;i<summ;i++){
QString value = boxList[x]->itemText(i);
if (inhalt == value) {
boxList[x]->setCurrentIndex(i);
}
}
}
}
n = n.nextSibling();
}
}
xmlfile.close();
}