From e395af1ac175d174e78138d974435a2556e775cd Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 27 Feb 2013 16:12:28 +0100 Subject: [PATCH] Debugger: Force shrinking of internal structures of log pane. Just keeping a maximum number of lines is not enough. Task-number: QTCREATORBUG-4620 Change-Id: Iedb947dc55e55fa3717da88c4e5762526423bbb6 Reviewed-by: hjk --- src/plugins/debugger/logwindow.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/plugins/debugger/logwindow.cpp b/src/plugins/debugger/logwindow.cpp index 237a7af6cbd..862c229e38a 100644 --- a/src/plugins/debugger/logwindow.cpp +++ b/src/plugins/debugger/logwindow.cpp @@ -189,11 +189,18 @@ public: void append(const QString &text) { const int N = 100000; - if (blockCount() > N) { - QTextBlock block = document()->findBlock(9 * N / 10); + const int bc = blockCount(); + if (bc > N) { + QTextDocument *doc = document(); + QTextBlock block = doc->findBlockByLineNumber(bc * 9 / 10); QTextCursor tc(block); - tc.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor); + tc.movePosition(QTextCursor::Start, QTextCursor::KeepAnchor); tc.removeSelectedText(); + // Seems to be the only way to force shrinking of the + // allocated data. + QString contents = doc->toHtml(); + doc->clear(); + doc->setHtml(contents); } appendPlainText(text); }