Seems to work as expected and documented. Note that pushing a command to the stack will always call redo() on the command object.
class DummyCmd : public QUndoCommand
{
public:
DummyCmd()
: QUndoCommand(){ qDebug() << "DummyCmd c-tor"; }
virtual void undo()
{ qDebug() << "undo"; }
virtual void redo()
{ qDebug() << "redo"; }
};
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
DummyCmd c1;
QUndoStack s;
qDebug() << "pushing to stack";
s.push(&c1);
qDebug() << "calling undo";
s.undo();
qDebug() << "canRedo after undo: " << s.canRedo();
s.redo();
qDebug() << "canRedo after redo: " << s.canRedo();
return a.exec();
}
Output:
DummyCmd c-tor
pushing to stack
redo
calling undo
undo
canRedo after undo: true
redo
canRedo after redo: false