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

Swagger spitting out xml response instead of json

spring spring-mvc swagger

I'm a week old in spring. I'm developing a pure RESTful API service using Spring + maven + Jackson. While exploring some best practices, I came across this, so I decided I'll be using swagger with ...

Object cannot be serialized because it does not have a parameterless constructor

c# web-services exchange-server exchangewebservices

I'm trying to write a web service that queries Exchange using the EWS API (2.2). I can get the data using Console.Write but I want to provide the data to users of my SOAP web service.