Search code examples
c++qtslotqmenuqaction

Problems with accessing newly created actions


I'm working on painter like application and i want to add an option of creating new actions in menu to manage subsets of points drawn. I'm creating new actions like so:

    void ImageViewer::on_New_setAct_triggered()
{
    setnumber++;
    newset = new QAction;
    newset->setText(QString("Set_" + QString::number(setnumber)));
    ui->menuSet->insertAction(ui->New_setAct, newset);
}

I want some slot to change variables upon clicking newly created action, but don't know how to access those actions. Any idea?


Solution

  • QAction has his own signals you can use them.

    For example:

    connect(newset, &QAction::triggered, this, &ImageViewer::on_newset_triggered);
    

    Then use the on_newset_triggered slot to handle this action.