Remove a line/block from QTextEdit

I'm struggling with block/line removal from QTextEdit. Code below should(?) work but it ends up in infinite loop for some unknown to me reason. I have a suspicion that next() and previous() are not welcome if QTextDocument is being edited.

QTextBlock block = document()->begin();
while (block.isValid()) {
    if (to_do_or_not_to_do(block)) {
        QTextCursor cursor(block);
        cursor.select(QTextCursor::BlockUnderCursor);
        cursor.removeSelectedText();
    }
    block = block.next();
}

Iterating using QTextDocument::findBlockByNumber() and deleting block in the same way as above didn't worked either.

I would appreciate if someone could point me into right direction on how to iterate trough all the blocks and remove them if needed.

P.S. In my particular case one block = one line. Qt 4.6.2, Ubuntu 10.04 x64

Answers


Changing it a little works for me:

while (block.isValid()) {
    if (to_do_or_not_to_do(block)) {
        QTextCursor cursor(block);
        block = block.next();
        cursor.select(QTextCursor::BlockUnderCursor);
        cursor.removeSelectedText();
    }
    else
        block = block.next();
}

Need Your Help

How to give color to placeholders

html css

I am making a form in which i am using placeholder like

PDB or ePUB format ebook reader for iPhone

objective-c xcode ios4 epub pdb-palm

I would like to ask you guys if there is any example source code available for Ebook reader for iPhone that loads any of these format files (PDB or ePUB).

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.