Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to remove last step from QUndoStack
I need to remove pushed last command from QUndoStack.
How can i do this, thank you for your help.
Hi and welcome
Im not sure you can.
For the push command
"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.
m.sue last edited by
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.
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.
m.sue last edited by m.sue
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 :-)
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.