QMenu* menu = new QMenu(); //add actions and submenus to the menu menu->addAction("Action 1"); QMenu* submenu = menu->addMenu("Submenu"); submenu->addAction("Submenu action 1"); //delete the menu menu->deleteLater();
QMenu* menu = new QMenu(); //add actions and submenus to the menu menu->addAction("Action 1"); QMenu* submenu = menu->addMenu("Submenu"); submenu->addAction("Submenu action 1"); //create a QTimer object to delete the menu later QTimer::singleShot(5000, menu, &QMenu::deleteLater);This code creates a new QMenu object, adds actions and submenus to it, then sets a QTimer to delete the menu object after 5 seconds using the QMenu::deleteLater() function. Package/Library: Qt.