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. Remove first QUndoCommand from QUndoStack
QtWS25 Last Chance

Remove first QUndoCommand from QUndoStack

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.1k 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.
  • S Offline
    S Offline
    szergejbubka
    wrote on last edited by
    #1

    Hi,

    My program uses the Qt Undo Framework. The individual commands may use a lot of memory, which can lead to insufficient memory. This could be handled by setting undoLimit, but it requires setting the limit prior to using the stack (i.e, when empty). I would like to detect, when the commands start using too much memory, and delete the first (few) commands (the oldest ones) to limit the memory usage of the undo stack.

    Looking into the source code, it seems, like the QUndoStackPrivate class could handle this (setting the limit when the stack is not empty), however it is hidden in Qt and QUndoStack checks the emptiness of the stack explicitly, and allows setting the limit only if it is empty.

    Is there a way to delete the first item of a undo stack (e.g. by reparenting the commands to a new stack)? If not, is there any reason, the emptiness of the stack is required to set the stack limit? It would be enough to check whether the current command is newer, than the new limit (just like QUndoStackPrivate does).

    Thanks.

    1 Reply Last reply
    1
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Out of curiosity, what makes your command eat so much memory ? If you need "infinite size", you could maybe use a temporary on disk cache to store the data you need.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        szergejbubka
        wrote on last edited by
        #3

        My application can handle and edit images, although it is not a image editor. Editing an image is one step in the undo stack, so I do not want to store each individual editing steps, thus I chose to store the whole image in the command. Furthermore it can handle several images simultaneously, which may come from DSLR cameras, so the memory requirement can easily become large.

        (Probably I could and will optimize the commands to use less memory, but my original question is somewhat independent of this very application.)

        Using disk cache could be a solution, indeed. However I do not need infinite stack. It would be fine to loose old commands from the stack if they use too much memory. But as the memory requirement of the commands cannot be predetermined (as it depends on the user actions), it would be nice if I could control the stack size dynamically based on the memory consumption of the commands.

        As I said, it seems that the guy, who coded the underlying QUndoStackPrivate class seems to have prepared for such situations, but for some reason, the other guy, who coded the QUndoStack class seems to have decided to hide that possibility from the developers and introduced an unnecessarily rigorous condition to allow changing the stack size.

        1 Reply Last reply
        1

        • Login

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