Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Managing memory in a QPlainTextEdit widget

Managing memory in a QPlainTextEdit widget

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 5.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KevinShaw
    wrote on last edited by
    #1

    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
    
    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DenisKormalev
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tobias.hunger
          wrote on last edited by
          #4

          Denis: I hope nobody would get the idea to repeat the truncating code all over the place!

          1 Reply Last reply
          0
          • C Offline
            C Offline
            calberto
            wrote on last edited by
            #5

            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".

            1 Reply Last reply
            0
            • K Offline
              K Offline
              KevinShaw
              wrote on last edited by
              #6

              Calerto,
              Thank you. That was exactly what I was looking for! :-)

                         Kevin
              
              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved