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. How to remove last step from QUndoStack
Forum Updated to NodeBB v4.3 + New Features

How to remove last step from QUndoStack

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.8k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    mete
    wrote on last edited by
    #1

    Hi,
    I need to remove pushed last command from QUndoStack.

    How can i do this, thank you for your help.

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

      Hi and welcome
      Im not sure you can.
      For the push command
      http://doc.qt.io/qt-5/qundostack.html#push
      it says
      "Once a command is pushed, the stack takes ownership of it. There are no getters to return the command, since modifying it after it has been executed will almost always lead to corruption of the document's state."

      So it dont sound like you cannot. I could be wrong. Did not work intensively with it.

      1 Reply Last reply
      1
      • m.sueM Offline
        m.sueM Offline
        m.sue
        wrote on last edited by
        #3

        Hi,
        the usual way to remove an command from the undo stack is to call the undo() function. Any consecutive new entry to the stack will eventually overwrite it then.

        But depending on what you want to do and why, there may be other options.
        -Michael.

        1 Reply Last reply
        2
        • M Offline
          M Offline
          mete
          wrote on last edited by
          #4

          Hi,
          Yes calling undo() solves my problem. But after that i don't want to user can make redo(). So i need remove this action from QUndoStack.

          1 Reply Last reply
          0
          • m.sueM Offline
            m.sueM Offline
            m.sue
            wrote on last edited by m.sue
            #5

            Hi,

            yeah that's when you really want to abort an action. I do it the following way:

            • call undo()
            • push an empty command to the undo stack (one that re-done does in fact nothing and has an empty string title)
            • call undo() again

            It's a mean trick, but it works :-)
            -Michael.

            M 1 Reply Last reply
            3
            • m.sueM m.sue

              Hi,

              yeah that's when you really want to abort an action. I do it the following way:

              • call undo()
              • push an empty command to the undo stack (one that re-done does in fact nothing and has an empty string title)
              • call undo() again

              It's a mean trick, but it works :-)
              -Michael.

              M Offline
              M Offline
              mete
              wrote on last edited by
              #6

              Hi Michael,
              Yes it seems this will solve my problem. As you say it'a a mean trick but that's ok. I will try, thank you very much.

              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