Quote 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


Qt Code:
  1. void Setting_Gui::ReadConfig()
  2. {
  3. QString configwget = APPLICATION_SETTING;
  4. QFile xmlfile(configwget);
  5. if(!xmlfile.open( QIODevice::ReadOnly ) ) {
  6. ErrorConfig("");
  7. }
  8. QString errorStr, obname, inhalt;
  9. int errorLine;
  10. int errorColumn;
  11.  
  12. QDomDocument doc("http://www.pulitzer.ch/2005/PuliCMS/1.0");
  13. if (!doc.setContent(&xmlfile,true, &errorStr, &errorLine, &errorColumn)) {
  14. QString error = (QString("Parse error at line %1, column %2:\n%3")
  15. .arg(errorLine)
  16. .arg(errorColumn)
  17. .arg(errorStr) );
  18. ErrorConfig(error);
  19. xmlfile.close();
  20. }
  21. QDomElement root = doc.documentElement();
  22. if( root.tagName() != "setting" ) {
  23. ErrorConfig("");
  24. }
  25. QDomNode n = root.firstChild();
  26. while( !n.isNull() )
  27. {
  28. QDomElement e = n.toElement();
  29. if( !e.isNull() )
  30. {
  31. for (int i=0;i<textList.size();i++){
  32. obname =QString(textList[i]->objectName());
  33. if( e.tagName() == obname ) {
  34. textList[i]->setText(decodeBase64(e.text()));
  35. }
  36. }
  37. for (int x=0;x<boxList.size();x++){
  38. obname =QString(boxList[x]->objectName());
  39. if( e.tagName() == obname ) {
  40. inhalt = decodeBase64(e.text());
  41. int summ = boxList[x]->count();
  42. for (int i=0;i<summ;i++){
  43. QString value = boxList[x]->itemText(i);
  44. if (inhalt == value) {
  45. boxList[x]->setCurrentIndex(i);
  46. }
  47. }
  48. }
  49. }
  50. n = n.nextSibling();
  51. }
  52. }
  53. xmlfile.close();
  54. }
To copy to clipboard, switch view to plain text mode