Results 1 to 7 of 7

Thread: Problem with Deleting QDomNode

  1. #1
    Join Date
    Jul 2009
    Posts
    39
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Problem with Deleting QDomNode

    Here my source code:
    Qt Code:
    1. QDomElement rootOfTag=fieldState.firstChild().firstChildElement(parent);
    2. QDomNodeList sameTags=rootOfTag.elementsByTagName(node.firstChild().toElement().tagName());
    3. for(uint i=0;i<sameTags.length();i++)
    4. {
    5. QDomNode nodeToReplace=sameTags.item(i);
    6. if(nodeToReplace.toElement().attribute("id")==node.firstChild().toElement().attribute("id"))
    7. {
    8. rootOfTag.removeChild(nodeToReplace);
    9. return true;
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    Although it enters into if part, it can't remove "nodeToReplace" . What can be my problem?

    Edit: nodeToReplace.nodeType() returns QDomNode::ElementNode, can problem related with that?
    Last edited by metdos; 15th July 2010 at 10:42.

  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: Problem with Deleting QDomNode

    Are you sure that nodeToReplace is a direct child of rootOfTag? How does a sample XML file look like?

  3. #3
    Join Date
    Jul 2009
    Posts
    39
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with Deleting QDomNode

    fieldState is QDomDocument,
    parent="Blocks"
    node.firstChild().toElement().tagName() returns "Block"

    Qt Code:
    1. <root>
    2. <Blocks>
    3. <Block id="1"></Block>
    4. <Block id="2"></Block>
    5. <Block id="3"></Block>
    6. </Blocks>
    7. </root>
    To copy to clipboard, switch view to plain text mode 

  4. #4
    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: Problem with Deleting QDomNode

    Hm, in the if block you have
    Qt Code:
    1. return true;
    To copy to clipboard, switch view to plain text mode 
    which exits your function, so how does the function definition looks like? Is fieldState a copy or a pointer so that the changes you make are propagated to your "real" QDomDocument? That's the only reason I can think of. May be you want check inside the if block if the node is deleted.

  5. #5
    Join Date
    Jul 2009
    Posts
    39
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with Deleting QDomNode

    Whole Function:
    Qt Code:
    1. bool FieldModel::updateNode(QDomNode node,QString parent){
    2.  
    3. QDomElement rootOfTag=fieldState.firstChild().firstChildElement(parent);
    4. QDomNodeList sameTags=rootOfTag.elementsByTagName(node.firstChild().toElement().tagName());
    5. for(uint i=0;i<sameTags.length();i++){
    6. QDomNode nodeToReplace=sameTags.item(i);
    7. if(nodeToReplace.toElement().attribute("id")==node.firstChild().toElement().attribute("id")){
    8. rootOfTag.removeChild(nodeToReplace);
    9. qDebug()<<"Hello:\n"<<fieldState.toString();
    10. return true;
    11. }
    12. }
    13. insertNode(node,parent);
    14. return true;
    15. }
    To copy to clipboard, switch view to plain text mode 

    Its output from line 9.

    Qt Code:
    1. Hello:
    2. "<FieldState>
    3. <Blocks>
    4. <Block id="3T">
    5. <OccupiedState>1</OccupiedState>
    6. <TanzimState>0</TanzimState>
    7. <ProtectionState>0</ProtectionState>
    8. <FailureState>0</FailureState>
    9. </Block>
    10. <Block id="001BT">
    11. <OccupiedState>1</OccupiedState>
    12. <TanzimState>0</TanzimState>
    13. <ProtectionState>0</ProtectionState>
    14. <FailureState>0</FailureState>
    15. </Block>
    16. </Blocks>
    17. <Switches/>
    18. <Signals/>
    19. <LevelCrossings/>
    20. <Routes/>
    21. </FieldState>
    22. "
    To copy to clipboard, switch view to plain text mode 

    fieldState is Class member and it is fine.

  6. #6
    Join Date
    Jul 2009
    Posts
    39
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with Deleting QDomNode


  7. #7
    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: Problem with Deleting QDomNode

    Quote Originally Posted by Lykurg View Post
    Are you sure that nodeToReplace is a direct child of rootOfTag?
    Quote Originally Posted by metdos View Post
    You could have had it earlier...

Similar Threads

  1. deleting QStringList
    By timmu in forum Qt Programming
    Replies: 5
    Last Post: 18th December 2009, 14:36
  2. QMdiSubWindows - Deleting
    By Kerubu in forum Newbie
    Replies: 1
    Last Post: 25th August 2009, 06:23
  3. QDomNode
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 14th September 2007, 07:11
  4. QDomNode
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 6th September 2007, 13:18
  5. The difference beteen QDomNode and QDomElement
    By elcuco in forum Qt Programming
    Replies: 4
    Last Post: 7th January 2006, 04:37

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.