QMenu* menu = new QMenu("Example Menu"); QAction* action1 = new QAction("Action 1", this); QAction* action2 = new QAction("Action 2", this); menu->addAction(action1); menu->addSeparator(); menu->addAction(action2);
QWidget* containerWidget = new QWidget(); QAction* action1 = new QAction("Action 1", this); QAction* action2 = new QAction("Action 2", this); action1->addTo(containerWidget); action2->addTo(containerWidget);This example creates a container widget and two QAction objects, then adds the actions to the container widget using the addTo method. The Qt framework is the package library used in these examples.