connect QAction a signal to QAction b slot AND connect QAction b signal to QAction a slot
Solved
General and Desktop
-
Hello,
I want to set up 3 actions (a, b and c) in a toolbar they all connect to the same slot in the mainwindow (Hello()), and when b is toggled then c is disabled and the other way: when c is toggled then b is disabled.
Something like that:m_toolBar = addToolBar(tr("selection")); QAction *aAct = new QAction(tr("&a"), this); aAct->setCheckable(true); connect(aAct, &QAction::triggered, this, &MainWindow::Hello); m_toolBar->addAction(aAct); QAction *bAct = new QAction(tr("&b"), this); bAct->setCheckable(true); connect(bAct, &QAction::triggered, this, &MainWindow::Hello); connect(bAct, &QAction::toggled, cAct, &QAction::setDisabled); m_toolBar->addAction(bAct); QAction *cAct = new QAction(tr("&c"), this); cAct->setCheckable(true); connect(cAct, &QAction::triggered, this, &MainWindow::Hello); connect(cAct, &QAction::toggled, bAct, &QAction::setDisabled); m_toolBar->addAction(cAct);
But when I do that, i have a crash. Someone can help me?
-
problem solved: action c was not initialized ...
I should have write that instead:m_toolBar = addToolBar(tr("selection")); QAction *aAct = new QAction(tr("&a"), this); aAct->setCheckable(true); connect(aAct, &QAction::triggered, this, &MainWindow::Hello); m_toolBar->addAction(aAct); QAction *bAct = new QAction(tr("&b"), this); bAct->setCheckable(true); connect(bAct, &QAction::triggered, this, &MainWindow::Hello); //connect(bAct, &QAction::toggled, cAct, &QAction::setDisabled); m_toolBar->addAction(bAct); QAction *cAct = new QAction(tr("&c"), this); cAct->setCheckable(true); connect(cAct, &QAction::triggered, this, &MainWindow::Hello); connect(cAct, &QAction::toggled, bAct, &QAction::setDisabled); connect(bAct, &QAction::toggled, cAct, &QAction::setDisabled); //<--- m_toolBar->addAction(cAct);