Is there a simpler way to send the same signal from many objects?
Hello,
I plan to use menus in my applications. There are many menus and sub menus. Only one sub menu needs one specified status. When I click other menus or sub menus I hope to change the status to normal one. But I do not hope to connect all of the menus or sub menus to the triggered signal.
Is there some smarter ways to resolve this problem? I mean just one line.
just like this:
if (x is triggered)
status changs
else
status changes back
Re: Is there a simpler way to send the same signal from many objects?
Could you explain more clearly what you mean by "status"? Does it refer to the presence of a checkbox next to the menu item?
If you have several menu item that are to do similar things, just with a different parameter, check out QSignalMapper.
Re: Is there a simpler way to send the same signal from many objects?
Thanks for you reply.
My question is like this:
There Menu1 that consists of sub menuA , sub menuB and so on
Menu2 that consists of sub menu AA, sub menu BB and so on
Menu3 that consists of sub menu AAA, sub menu BBB and so on
... ....
When I click the sub menu AA, The value of status becomes true. But when I click any other menu except sub menu AA, I hope the value of status will become false. I do not hope to connect each sub menu with the signal because there are too many sub menus.
connect(menuAction, SIGNAL(triggered()), this, SLOT(valueChanged));
My question is: Is there some way we can do it in a simpler way?
Re: Is there a simpler way to send the same signal from many objects?
did you see this signal QMenu::triggered.
an example
Code:
...
QMenu *menu
= menuBar
()->addMenu
("Test");
menu->addAction(action);
menu->addAction(action);
menu->addAction(action);
menu->addAction(action);
menu->addAction(action);
connect(menu,
SIGNAL(triggered
(QAction *)),
SLOT(processAction
(QAction *)));
...
Re: Is there a simpler way to send the same signal from many objects?
Have you looked at QActionGroup - I think you make a group of QActions mutually exclusive.
Pete