QMenu menu("Menu", this); QAction* action1 = new QAction("Action 1", this); QAction* action2 = new QAction("Action 2", this); menu.addAction(action1); menu.addAction(action2); QAction* selectedAction = menu.exec(QCursor::pos()); if (selectedAction == action1) { // Action 1 was selected } else if (selectedAction == action2) { // Action 2 was selected }This example creates a menu with two actions and executes it. The selected action is then compared to the created actions to determine which one was selected. The Qt library provides the necessary functionality for creating menus and executing them in a user-friendly way.