Results 1 to 6 of 6

Thread: Saving rich text to XML file

  1. #1
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Saving rich text to XML file

    How can I save a QTextEdit's text and preserve it's current formating?

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Saving rich text to XML file

    Since a subset of html formatting is used, you can simply save the text as html:
    http://doc.qt.nokia.com/4.6/qtextedit.html#html-prop

  3. #3
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Saving rich text to XML file

    Thanks for the reply.
    I know(can't implement it ..) that I can save the QTextEdit's QTextDocument formatting to a QTextFormat.toListFormat (). But the I would have to save the plain text and the formating info to the xml file.
    Saving text to html does seem to be easier, but is it better?
    Last edited by been_1990; 1st August 2010 at 18:44.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Saving rich text to XML file

    Better for what purpose? Your stated aim of saving the content and formatting of a QTextEdit is met by saving the result of QTextEdit::toHtml() and restoring it using QTextEdit::setHtml(). If you want to put that inside another XML document element then you probably want to insert it as a CDATA block.

  5. #5
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Saving rich text to XML file

    I mean "what's the recommended way?", if there is such a thing. There's always a way that will be better, more flexible, reliable,etc..

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Saving rich text to XML file

    I think the HTML option is the most straightforward. I'm not certain what it does with embedded images, like Text Object Example, so you might have to experiment if that is your situation. Worst case is having to go to the underlying QTextDocument to develop a serialisation method based on the blocks structure.

Similar Threads

  1. Considerations for a GUI with rich text?
    By hackerNovitiate in forum Newbie
    Replies: 1
    Last Post: 2nd April 2010, 06:39
  2. How to use rich text in a QComboBox?
    By aarunt1 in forum Qt Programming
    Replies: 3
    Last Post: 19th March 2010, 20:20
  3. Problems saving a text file
    By aarelovich in forum Qt Programming
    Replies: 3
    Last Post: 27th September 2009, 14:39
  4. QTextEdit + paste rich text as plain text only
    By Yong in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2008, 16:45
  5. Painting Rich Text
    By xanthine in forum Qt Programming
    Replies: 7
    Last Post: 15th April 2006, 23:35

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.