Results 1 to 2 of 2

Thread: process QTextDocument and recognize newlines?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2008
    Posts
    14
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default process QTextDocument and recognize newlines?

    hi guys,

    i'm currently trying to convert the contents of a QTextDocument to another format, simply by processing it pretty much hierarchically:
    - process each frame/table
    - process each block/list
    - process each fragment

    the problem with this method is that a block's or fragments' text doesn't contain any newline characters (since they are converted to "ParagraphSeparators").

    i tried to find the newline characters by selecting the current block with a new QTextCursor and then using a QTextDocumentFragment to get the "plain text".
    QTextCursor::select( QTextCursor::BlockUnderCursor ) also selects the ParagraphSeparator before the block.
    i created a new QTextDocumentFragment and gave the previously created QTextCursor as an argument in its constructor.
    now QTextDocumentFragment::toPlainText() also contained the character before the block and when QTextDocumentFragment::toPlainText().at( 0 ) == '\n', i knew there was an '\n' before the current block.
    i can also post the according code to this if that helps.

    even though it seems kind of "quick&dirty", it works for a single newline before a block.
    but if, for example, there was an empty line before a new block ("\n\nBlockText"), the 2 newlines ("\n\n") were put together as one ParagraphSeparator and therefore using QTextDocumentFragment as i explained above doesn't make it possible to know if there was an empty line before a block.

    so... sorry for writing such a long text, but i found it pretty difficult to explain (probably because i'm not a native speaker ...).
    i hope someone can help me out here.
    maybe i just didn't find some easy trick, or maybe even my whole approach to processing the QTextDocument is crap?

    thanks in advance!

    sincerely,
    julian
    Last edited by -=Freaky=-; 21st June 2009 at 12:26.

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.