In this example, we create a new QActionGroup object and add two QAction objects to it. We can now use this group to control which actions can be active at any given time. Code example #2: Setting the active action in a group.C++
In this example, we use the setSelectedAction() function to select the second action in the group. This will automatically deselect any other actions that may have been selected previously. Code example #3: Processing the triggered signals of the group actions.C++ // Connecting actions to the same slot connect(action1, &QAction::triggered, this, &MyClass::onActionTriggered); connect(action2, &QAction::triggered, this, &MyClass::onActionTriggered); // Slot function void MyClass::onActionTriggered(QAction* action) { if (action) { // Do something with the selected action } } ``` In this example, we connect the triggered signal of both actions to the same slot function onActionTriggered(). Whenever an action in the group is triggered (i.e. clicked by the user), this slot function will be called with the corresponding QAction object as its argument. The Qt framework package library contains the QActionGroup class and related classes for building user interfaces in C++ using the Qt framework.