Results 1 to 6 of 6

Thread: QStringList withing QDomText

  1. #1
    Join Date
    Apr 2008
    Posts
    196
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 8 Times in 6 Posts
    Wiki edits
    1

    Default QStringList withing QDomText

    I want to append a QDomText which is a QStringList to an existing QDomElement. Currently I use the following:
    Qt Code:
    1. QDomText text = doc.createTextNode(strList.join("\n"));
    2. element.appendChild(text);
    3. element.setAttribute("size", strList.size());
    To copy to clipboard, switch view to plain text mode 

    So for this example the output would be:
    Qt Code:
    1. <node1>
    2. <data>
    3. <element size="4" >Article1
    4. Article2
    5. Article3
    6. Article4</element>
    7. </data>
    8. </node1>
    To copy to clipboard, switch view to plain text mode 

    I want to make it better readable, so my question is how can i use these functions to produce:
    Qt Code:
    1. <node1>
    2. <data>
    3. <element size="4" >
    4. Article1
    5. Article2
    6. Article3
    7. Article4
    8. </element>
    9. </data>
    10. </node1>
    To copy to clipboard, switch view to plain text mode 

    Is there a beautifier within the QtXml which i couldn't found? I seem to remember that xerces will do so.
    How can i do so with standard Qt tools?

    Regards

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: QStringList withing QDomText

    what are you using to display the xml data ?? My guess is QListWidget..
    QTextEdit is good for displaying xml.
    Hint :
    Qt Code:
    1. QString xmlString;
    2. QTextStream stream(&xmlString);
    3. myRootElement.save(stream,4);
    4.  
    5. QTextEdit::setPlainText(xmlString);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Apr 2008
    Posts
    196
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 8 Times in 6 Posts
    Wiki edits
    1

    Default Re: QStringList withing QDomText

    Quote Originally Posted by aamer4yu View Post
    what are you using to display the xml data ?? My guess is QListWidget..
    QTextEdit is good for displaying xml.
    Hint :
    Qt Code:
    1. QString xmlString;
    2. QTextStream stream(&xmlString);
    3. myRootElement.save(stream,4);
    4.  
    5. QTextEdit::setPlainText(xmlString);
    To copy to clipboard, switch view to plain text mode 
    This code snippet doesn't work. The only thing what the snippet does is adding 4 spaces instead of 1 for every node.

    I want to write the QStringList within QDomText so that when a user opens the xml file with his prefered editor he knows that this is a list of values.

    Once more:
    Currently this is written:
    Qt Code:
    1. <element size="4" >Article1
    2. Article2
    3. Article3
    4. Article4</element>
    To copy to clipboard, switch view to plain text mode 

    And this should be, but the question is how?
    Qt Code:
    1. <element size="4" >
    2. Article1
    3. Article2
    4. Article3
    5. Article4
    6. </element>
    To copy to clipboard, switch view to plain text mode 

    Regards

  4. #4
    Join Date
    Apr 2008
    Posts
    196
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 8 Times in 6 Posts
    Wiki edits
    1

    Default Re: QStringList withing QDomText

    *Push*

    Does nobody know a way on how to do this?

    Regards

  5. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: QStringList withing QDomText

    hmm,,, seems its more of spacing prob than i thought...
    first u are using strList.join("\n"); u also need to prepend and append '\n' to it, right ?

    still u wont get the efftect...bec after new line, you dont know how many spaces to leave..
    do thats another function to calculate space for current node, relative to the root node.

    hope u get the idea now..

    anyhow I feel ther might better way to do what u are doing... cud u show some more code or snapshots ??

  6. #6
    Join Date
    Apr 2008
    Posts
    196
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 8 Times in 6 Posts
    Wiki edits
    1

    Default Re: QStringList withing QDomText

    I saw this from various other xml files, so i can do the following:
    Qt Code:
    1. <element size="4" >
    2. <string>Article1</string>
    3. <string>Article2</string>
    4. <string>Article3</string>
    5. <string>Article4</string>
    6. </element>
    To copy to clipboard, switch view to plain text mode 
    but i think with the other way, a user can faster recognition that the content is a list.
    How can i get the space for a current node?

    Regards

Similar Threads

  1. QStringList
    By jaca in forum Qt Programming
    Replies: 5
    Last Post: 17th May 2008, 11:12
  2. QStringList in QObject::connect
    By DPinLV in forum Qt Programming
    Replies: 6
    Last Post: 6th September 2006, 18:01
  3. Cannot queue arguments of type 'QStringList'
    By vfernandez in forum Qt Programming
    Replies: 2
    Last Post: 19th April 2006, 21:48

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.