Results 1 to 3 of 3

Thread: QDomDocumen save method doesn't work!

  1. #1
    Join Date
    May 2010
    Location
    China
    Posts
    66
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Smile QDomDocumen save method doesn't work!

    i want to create a file and write some xml code in it use the below code like this ,but it don't save anything ,anyone could help me
    Qt Code:
    1. QString xmlAddress=projectAddress;
    2. xmlAddress+="//";
    3. xmlAddress+=projectName;
    4. xmlAddress+=".drdp";//项目的后缀名为.drdp
    5.  
    6.  
    7. QDomElement project=doc.createElement("Project");
    8. QDomElement projectInformation=doc.createElement("ProjectInformation");
    9. QDomElement createTime=doc.createElement("CreateTime");
    10. QDomElement name=doc.createElement("Name");
    11. QDomElement author=doc.createElement("Author");
    12. QDomElement description=doc.createElement("Description");
    13. QDomElement unit=doc.createElement("Unit");
    14. QDomElement type=doc.createElement("Type");
    15.  
    16.  
    17. QDomElement files=doc.createElement("Files");
    18. QDomElement chart2d=doc.createElement("Chart2D");
    19. QDomElement chart3d=doc.createElement("Chart3D");
    20. QDomElement data=doc.createElement("Data");
    21.  
    22. QDomElement databases=doc.createElement("Databases");
    23.  
    24.  
    25. doc.appendChild(project);
    26.  
    27.  
    28. project.appendChild(projectInformation);
    29. project.appendChild(files);
    30. project.appendChild(databases);
    31.  
    32. projectInformation.appendChild(createTime);
    33. projectInformation.appendChild(name);
    34. projectInformation.appendChild(author);
    35. projectInformation.appendChild(description);
    36. projectInformation.appendChild(unit);
    37. projectInformation.appendChild(type);
    38.  
    39.  
    40. QDomText txtCreateTime=doc.createTextNode(projectCreateTime.toString(Qt::DateFormat::ISODate));
    41. QDomText txtAuthor=doc.createTextNode(projectAuthor);
    42. QDomText txtName=doc.createTextNode(projectName);
    43. QDomText txtDescription=doc.createTextNode(projectDescription);
    44. QDomText txtType=doc.createTextNode("TextType");
    45. QDomText txtUnit=doc.createTextNode("TextUnit");
    46.  
    47. createTime.appendChild(txtCreateTime);
    48. name.appendChild(txtName);
    49. author.appendChild(txtAuthor);
    50. description.appendChild(txtDescription);
    51. unit.appendChild(txtUnit);
    52. type.appendChild(txtType);
    53. QDomNode xmlNode = doc.createProcessingInstruction("xml","version=\"1.0\" encoding=\"utf-8\"");
    54.  
    55. doc.insertBefore(xmlNode, doc.firstChild());
    56.  
    57.  
    58.  
    59.  
    60.  
    61.  
    62. QTextStream out(&xmlAddress);
    63.  
    64.  
    65.  
    66.  
    67.  
    68. doc.save(out,4);
    To copy to clipboard, switch view to plain text mode 
    Last edited by xiongxiongchuan; 1st June 2010 at 10:43.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QDomDocumen save method doesn't work!

    Well, it is perfectly saved, but not where you expect it! It is saved in your QString xmlAddress. If you want to save it to a file, specified by xmlAddress, you have to use QFile first!


    And did you noticed, that you have used the wrong tags to indicate that your text is c++ code? Please use the [code] tags next time, which makes your code much more readable.

  3. The following user says thank you to Lykurg for this useful post:

    xiongxiongchuan (1st June 2010)

  4. #3
    Join Date
    May 2010
    Location
    China
    Posts
    66
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDomDocumen save method doesn't work!

    thank you i have correct this probrem

    Quote Originally Posted by Lykurg View Post
    Well, it is perfectly saved, but not where you expect it! It is saved in your QString xmlAddress. If you want to save it to a file, specified by xmlAddress, you have to use QFile first!


    And did you noticed, that you have used the wrong tags to indicate that your text is c++ code? Please use the [code] tags next time, which makes your code much more readable.

Similar Threads

  1. QPixmap::save() doesn't work
    By Persoontje in forum Qt Programming
    Replies: 2
    Last Post: 25th November 2009, 11:53
  2. QThread::start() doesn't invoke run() method
    By seim in forum Qt Programming
    Replies: 2
    Last Post: 5th February 2009, 17:09
  3. QHttp RFC Method PUT not work.
    By patrik08 in forum Qt Programming
    Replies: 4
    Last Post: 19th May 2007, 15:44
  4. Replies: 6
    Last Post: 3rd November 2006, 11:53
  5. QImage : trouble with save() method
    By krivenok in forum Qt Programming
    Replies: 12
    Last Post: 3rd May 2006, 20:55

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.