I have a GUI application, the main part of which is QPlainTextEdit . It is used to display the application log, and as such, the associated text grows line by line to infinity.
Since the application is designed to work for a very long time, I need to limit the memory that will be allocated for this log. Therefore, I want to have some parameter maxNumLines or maxNumCharacters , which ensures that the history will be truncated upon reaching, i.e. Headers will be deleted as new lines are added (rotation of the aka journal).
For this, I found functions
// get the associated text QString toPlainText () const // set the associated text void setPlainText ( const QString & text )
Therefore, something like this untested code is likely to do the trick:
QString &tmp = pte.toPlainText(); while (tmp.size() > 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 );
Is it possible to remove the first row from QPlainTextEdit ? Perhaps there are other Qt text GUI elements that are better suited for this task (set the maximum number of lines and truncate at the top of the list), for example. somehow display a QStringList in which I could store the strings (st I could easily erase(0) )?
Or does QPlainTextEdit eventually implement such an upper bound for the size of the associated QString?
moooeeeep
source share