Search code examples
c++qtundoslotredo

triggering redo after undo


I am trying to make it to where redo is only visible after undo is used. I cannot seem to get it to work. I know there is something wrong with my signals and slots i just cant figure out how to get it to work.

here is the code for the undo and redo signal slots:

    cutAct->setEnabled(false);
    copyAct->setEnabled(false);
    undoAct->setVisible(false);
    redoAct->setVisible(false);
    connect(textEdit, SIGNAL(copyAvailable(bool)), cutAct, SLOT(setEnabled(bool)));
    connect(textEdit, SIGNAL(copyAvailable(bool)), copyAct, SLOT(setEnabled(bool)));
    connect(textEdit->document(), SIGNAL(modificationChanged(bool)), undoAct, SLOT(setVisible(bool)));
    connect(undoAct, SIGNAL(triggered()), redoAct, SLOT(setVisible(bool)));

Solution

  • ui->undoBtn->setEnabled(false);
    ui->redoBtn->setEnabled(false);
    connect(ui->textEdit,SIGNAL(redoAvailable(bool)),ui->redoBtn,SLOT(setEnabled(bool)));
    connect(ui->textEdit,SIGNAL(undoAvailable(bool)),ui->undoBtn,SLOT(setEnabled(bool)));
    

    Put it in the constructor and the undo and redo buttons will become available when is action for them