Results 1 to 7 of 7

Thread: recursive problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2007
    Posts
    91
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    60

    Default recursive problem

    I used DOM to parse an XML file

    Qt Code:
    1. QDomNode node = root.firstChild();
    2. if (!node.isNull()) {
    3. node = findTag(node, "Communication");
    4. //do something with node
    5. }
    6.  
    7. QDomNode DomParser::findTag(QDomNode &node, const QString &tag)
    8. {
    9. if (node.toElement().tagName() == tag) {
    10. return node;
    11. }else {
    12. if (hasChild(node)) {
    13. node = node.firstChild();
    14. findTag(node, tag);
    15. }else {
    16. while (!hasSibling(node)) {
    17. if (hasParent(node))
    18. node = node.parentNode();
    19. else
    20. QMessageBox::information(0, "Error", "Can not find Tag");
    21. }
    22. node = node.nextSibling();
    23. findTag(node, tag);
    24. }
    25. }
    26. }
    27.  
    28. inline bool DomParser::hasParent(const QDomNode &node)
    29. {
    30. if( !node.parentNode().isNull())
    31. return true;
    32. else
    33. return false;
    34. }
    35.  
    36. inline bool DomParser::hasSibling(const QDomNode &node)
    37. {
    38. if( !node.nextSibling().isNull())
    39. return true;
    40. else
    41. return false;
    42. }
    43.  
    44. inline bool DomParser::hasChild(const QDomNode &node)
    45. {
    46. return node.hasChildNodes();
    47. }
    To copy to clipboard, switch view to plain text mode 

    There is always an error in "qatomic_windows.h"
    Qt Code:
    1. inline int q_atomic_decrement(volatile int *ptr)
    2. { return _InterlockedDecrement(reinterpret_cast<volatile long *>(ptr)); }
    To copy to clipboard, switch view to plain text mode 

    Is there anything wrong in my code ?
    Last edited by Shawn; 16th October 2007 at 12:27.

Similar Threads

  1. Graphics view display problem.
    By kiranraj in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2007, 08:08
  2. [QMYSQL] connection problem
    By chaos_theory in forum Installation and Deployment
    Replies: 5
    Last Post: 2nd July 2007, 10:52
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 15:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 22:36
  5. Replies: 16
    Last Post: 7th March 2006, 16:57

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
  •  
Qt is a trademark of The Qt Company.