Results 1 to 7 of 7

Thread: QDomElement::text() returns corrupted strings

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QDomElement::text() returns corrupted strings

    Hi,

    please explain what is wrong with my code:

    Qt Code:
    1. #include <QDomDocument>
    2. #include <QFile>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6.  
    7. QFile file("c:\\bugtest.xml");
    8. file.open(QIODevice::ReadOnly);
    9. doc.setContent(&file);
    10. file.close();
    11.  
    12. QDomElement docElem = doc.documentElement();
    13.  
    14. QDomNode n = docElem.firstChild();
    15. while(!n.isNull()) {
    16. QDomElement e = n.toElement(); // try to convert the node to an element.
    17. if(!e.isNull()) {
    18. if (e.tagName() == "value" && e.hasAttribute("id"))
    19. {
    20. QString id = e.attribute("id");
    21. QString data = e.text();
    22. } /* crash point */
    23. n = n.nextSibling();
    24. }
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 
    The code crashes at the point marked, when deleting QString data - heap corrupted.

    The document is:

    xml Code:
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <data>
    3. <value id="some_id">Some value</value>
    4. </data>
    To copy to clipboard, switch view to plain text mode 

    Windows XP, Visual studio 2005, QT 4.5.0-rc1 (also 4.3.5).


    Thanks in advance.
    Last edited by wysota; 7th March 2009 at 12:20. Reason: missing [code] tags

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.