How can I save a QTextEdit's text and preserve it's current formating?
How can I save a QTextEdit's text and preserve it's current formating?
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
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.
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.
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..
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.
Bookmarks