PDA

View Full Version : QMenu, QActions calling slots with an parameter?



conti
14th March 2012, 13:46
Hi i have a QMenu which is used as a popup menu.
This menu contains a sub menu which can contain up to 10 sub menu items which are added dynamicaly. I would like to call the same slot from this 10 submenu items when triggered, but with an id parameter (1-10). How can i do this? When creating the menu action i can only do something like this menu->addAction("Menu item 1",this,SLOT(dowork(int))).
how can i make the action do something like this: menu->addAction("Menu item 1",this,SLOT(dowork(1))) ?
Is there a way to tell the action to send a parameter to the slot?

high_flyer
14th March 2012, 15:40
There are at least two ways, but the simpler one would be to use QSignalMapper.

conti
14th March 2012, 16:16
The QSignalMapper worked, thanks.