Get item in dynamic menu
-
I'm very new in Qt and I'm stuck with Qmenu functionallity, I need to create a dynamic menu attached to an Action, I don't know how to get wich item I clicked
@
ui->mainToolBar->addAction(ui->actionPlus);
AddItems = new QMenu;
for(int i = 0; i < 10; i++){// just for testing
AddItems->addAction("Item " + QString::number(i), this, SLOT(AddItems_triggered()));
}//....
ui->actionPlus->setMenu(AddItems);
//.....
void MainWindow::AddItems_triggered()
{
qDebug() << "testing....";
}
@is there a way to get the menu Item clicked of the menu?
I'm Lost, I keep Searching but I allway get the same search results -
Hi,
You should use QMenu::triggered(QAction *)
-
based on your answer, I google again, and I got this: http://stackoverflow.com/questions/9187538/qt-how-to-add-a-list-of-qactions-to-qmenu-and-handle-them-with-a-single-slot
from where I could get this:
@
for(int i = 1; i < 3; i++){
QAction action = new QAction("Item " + QString::number(i),this);
action->setData(i);
AddItems->addAction(action);
}
AddItems->addSeparator();
AddItems->addAction("Other Items 1", this, SLOT(tempFuncd()));
AddItems->addAction("Other Items 2", this, SLOT(tempFuncd2()));
connect(AddItems, SIGNAL(triggered(QAction)), this, SLOT(AddItems_triggered(QAction*)));
@I guest that in the AddItems_triggered function I could do a switch to do something or just ignore
-
You could also use a "QSignalMapper":http://qt-project.org/doc/qt-4.8/qsignalmapper.html
-
sorry to bother but, could u put a link where I could see an example of this?
I'm Lost here, -
"Qt Quarterly 10":http://doc.qt.digia.com/qq/qq10-signalmapper.html