title: QPlainTextEdit truncate history linewise
body: <p>I have a GUI application whose main part is a <a href="http://doc.qt.nokia.com/4.7-snapshot/qplaintextedit.html" rel="noreferrer">QPlainTextEdit</a>. It is used to display a log of the application, and as such the associated text grows line by line ad infinitum.</p>
  
  <p>As the application is intended to run very long, I need to limit the memory that will be allocated for this log. Therefore I want to have some <code>maxNumLines</code> or <code>maxNumCharacters</code> parameter that will make sure the history will be truncated when reached, i.e. the head lines will be removed as new lines are appended (a.k.a. <em>log rotation</em>).</p>
  
  <p>To achieve this I found the functions</p>
  
  <pre><code>// get the associated text
  QString toPlainText () const
  
  // set the associated text
  void setPlainText ( const QString &amp; text )
  </code></pre>
  
  <p>Therefore something like this untested code would probably do the trick:</p>
  
  <pre><code>QString &amp;tmp = pte.toPlainText();
  while (tmp.size() &gt; maxNumCharacters) {
    // remove lines from the head of the string until the desired size is reached
    // removes nothing if "\n" could not be found
    tmp.remove(0, tmp.indexOf("\n")+1);
  }
  pte.setPlainText( tmp );
  </code></pre>
  
  <p>Is this the way to go to remove the first line(s) from the <code>QPlainTextEdit</code>? Are there probably other Qt Text GUI elements that would better fit to this task (set a maximum number of lines and truncate at the head of the list), e.g. somehow display a <code>QStringList</code> in which I could store the lines (s.t. I could easily <code>erase(0)</code>)?</p>
  
  <p>Or does the QPlainTextEdit eventually implement such upper bound for the size of the associated QString after all?</p>