Originally Posted by
rajesh
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
);
ErrorConfig("");
}
int errorLine;
int errorColumn;
QDomDocument doc
("http://www.pulitzer.ch/2005/PuliCMS/1.0");
if (!doc.setContent(&xmlfile,true, &errorStr, &errorLine, &errorColumn)) {
.arg(errorLine)
.arg(errorColumn)
.arg(errorStr) );
ErrorConfig(error);
xmlfile.close();
}
if( root.tagName() != "setting" ) {
ErrorConfig("");
}
while( !n.isNull() )
{
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();
}
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();
}
To copy to clipboard, switch view to plain text mode
Bookmarks