PDA

View Full Version : QUndoStack problem



swiety
24th October 2007, 17:38
I have a QTreeWidget with rows:

A
B
C
D

and commands:
1:


QUndoStack *stack = new QUndoStack();
stack->push( new InsertCommand( new QTreeWidgetItem(), 0 ) );
stack->undo(); // insertTopLevelItem( 0, newitem );
Result:

NewItem
A
B
C
D

2:


InsertCommand *cmd = new InsertCommand( new QTreeWidgetItem(), 0 );
cmd->undo(); //insertTopLevelItem( 0, newitem );
Result:

NewItem
B
C
D

Why I have two different results. What's the difference between 1 and 2?

jacek
24th October 2007, 21:57
Does the InsertCommand's constructor do anything with the tree widget?

Qt invokes redo() to perform the command when you push it onto the stack, but it seems that in the first case the command was performed twice.