Code for an Undo option

  • How to code for an undo option ....Any help is appreciated.

  • Lifetime Qt Champion

    hi and welcome
    there is support via

    But that said, it really depends on what you want to undo and how many levels back.
    So it comes down to what kinda of data your application handles and what you do it and
    what undo will do.

    Simple undo from say Delete is easy, as you can keep lasted
    deleted object around until next delete.

    you can have a look at this example

  • @mrjj i am developing Linux calculator for that the undo is everything that we entered will be going in reverse format....i hope you understood..

  • Lifetime Qt Champion

    Well you want to be able to undo actual sub calculations
    or just the entered text ?
    or what will it undo ?

  • yup exactly like.....
    5 + 4 + 3
    result = 12
    if again added
    12 + 2
    result = 14

    and now when you hit undo it should show the previous expression
    12 + 2
    again undo
    ull get 12
    5 + 4 + 3
    "no undo history"

  • Lifetime Qt Champion

    Ok so the easy way is just to store a QUndoCommand each time
    the state changes. Like add or remove digit.
    Enter should be a bit special as you will have to keep the
    buffer before doing the calc.

    I think the undo system will fully support your case.

    Alternative, you could just store the current Input (1+2)
    in a QStringList each time its changed
    and then just take last string from there on undo.

  • Ok thank you very much You were helpfull...

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.