PDA

View Full Version : QTextDocument::blockCount is always 1



thomaspu
13th November 2012, 15:50
I have a QTextEdit that I'm adding text to with insertHtml(). Its a combination of plaintext and true html thats added with that method. I'm using the QTextEdit as a logfile viewer of sorts. The trouble that I have is after a while, the QTextEdit has lots and lots of text in it. I want to create a cap on the number of lines that the QTextEdit displays.

For starters, I need to get the number of text lines. What is confusing is that I call QTextEdit->document()->blockCount() and it always returns 1. I tried the more obvious lineCount() and it too returned 1. However the characterCount() returns what looks like a correct value.

Theres like 100+ lines of text. Any ideas why blockCount is returning 1?

Paul

wysota
14th November 2012, 00:00
I would assume that the way you use HTML makes the document keep all the data in one paragraph (block). Maybe instead of using insertHtml() you should use QTextCursor API?