void MyClass::pressMenu()
{
QAction* your_action
= qobject_cast<QAction
*>
(sender
());
// Your code
}
void MyClass::pressMenu()
{
QAction* your_action = qobject_cast<QAction*> (sender());
// Your code
}
To copy to clipboard, switch view to plain text mode
By this action you get your action. Then you change view according to selected action! Their actions you should to do in the slot (for example it's name is pressMenu)!
class MyClass
{
// your variables and functions
private slots:
void pressMenu();
}
class MyClass
{
// your variables and functions
QAction* myActions[2];
private slots:
void pressMenu();
}
To copy to clipboard, switch view to plain text mode
- in header
for(int i=0; i<2; ++i)
{
connect(myActions[i], SIGNAL(triggered()), this, SLOT(pressMenu()));
}
for(int i=0; i<2; ++i)
{
myActions[i] = new QAction(this);
connect(myActions[i], SIGNAL(triggered()), this, SLOT(pressMenu()));
}
To copy to clipboard, switch view to plain text mode
- in source
For example use this code!
Bookmarks