I have a QTreeWidget with rows:

A
B
C
D

and commands:
1:
Qt Code:
  1. QUndoStack *stack = new QUndoStack();
  2. stack->push( new InsertCommand( new QTreeWidgetItem(), 0 ) );
  3. stack->undo(); // insertTopLevelItem( 0, newitem );
To copy to clipboard, switch view to plain text mode 
Result:

NewItem
A
B
C
D

2:
Qt Code:
  1. InsertCommand *cmd = new InsertCommand( new QTreeWidgetItem(), 0 );
  2. cmd->undo(); //insertTopLevelItem( 0, newitem );
To copy to clipboard, switch view to plain text mode 
Result:

NewItem
B
C
D

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