java
sql
html
php
iphone
c
xml
ajax
android
ruby-on-rails
mysql
visual-studio
multithreading
silverlight
html5
oracle
apache
api
postgresql
dom
You can associate an index (or any other data) to each action when they are created with QAction::setData and connect the signal QMenu::triggered(QAction*) to your slot.
QAction::setData
QMenu::triggered(QAction*)
You'll then be able to retrieve the data through the QAction::data() function of your slot parameter.
QAction::data()
MyClass::MyClass() { // menu creation for(...) { QAction *action = ...; action->setData(10); ... menu->addAction(action); } // only one single signal connection connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(mySlot(QAction*))); } void MyClass::mySlot(QAction *action) { int value = action->data().toInt(); }
Other methods: signal mapping or the use of sender(), are explained in that article of Qt Quaterly.
sender()