Managing memory in a QPlainTextEdit widget
-
wrote on 6 Oct 2010, 09:23 last edited by
I have a QPlainTextEdit widget which I use as a log window for a manufacturing app. The number of events logged to this window are large. I would like to limit the window to, say, the last 10,000 lines. First, how can I track the memory usage of a widget? Second, is there a way to clip or limit the number of lines of data in a widget like this. Thanks!
Kevin
-
wrote on 6 Oct 2010, 10:05 last edited by
Memory usage in bytes should be around twice the number of characters in the edit since QString is using UTF16 to represent unicode values.
Of course you can remove lines you do not care about anymore: Just delete anything but the last 10k of lines whenever you add a new line.
-
wrote on 6 Oct 2010, 11:36 last edited by
In addition to Tobias answer I can say that it will be better to create a subclass of QPlainTextEdit which will do this truncation internally. Just to not copy/paste this operation around a project.
-
wrote on 6 Oct 2010, 13:31 last edited by
Denis: I hope nobody would get the idea to repeat the truncating code all over the place!
-
wrote on 12 Oct 2010, 06:30 last edited by
Maybe @QPlainTextEdit::setMaximumBlockCount()@ fit your needs. It limits the number of paragraphs for you, by removing the oldest. As documentation says, it is "useful in a log viewer".
-
wrote on 16 Oct 2010, 08:03 last edited by
Calerto,
Thank you. That was exactly what I was looking for! :-)Kevin
1/6