QMenu* fileMenu = new QMenu(this); QAction* newAction = new QAction(tr("New"), this); QAction* openAction = new QAction(tr("Open"), this); QAction* saveAction = new QAction(tr("Save"), this); fileMenu->addAction(newAction); fileMenu->addAction(openAction); fileMenu->addAction(saveAction);
QMenu* editMenu = new QMenu(this); QListIn this example, we create a new QMenu object called editMenu. We also create a QList of QAction objects called editActions and add three new QAction objects to it. We then add all the QAction objects from the QList to the QMenu using the addActions() function. Package library: Qt Widgets module of the Qt framework.editActions; editActions.append(new QAction(tr("Cut"), this)); editActions.append(new QAction(tr("Copy"), this)); editActions.append(new QAction(tr("Paste"), this)); editMenu->addActions(editActions);