quitAction = new QAction(tr("&Quit"),this); quitAction->setIcon(QIcon(":/quit.ico")); quitAction->setShortcut(QKeySequence::Quit); /// quitAction->setShortcut(tr("Ctrl+Q")); //Another short cut binding method quitAction->setStatusTip(tr("Quit the program")); connect(quitAction,SIGNAL(triggered()),this,SLOT(close()));
aboutQtAction = new QAction(tr("About Qt"),this); aboutQtAction->setStatusTip(tr("Show the Qt library's About Box")); connect(aboutQtAction,SIGNAL(triggered()),qApp,SLOT(aboutQt()));
连接
1 2 3 4
/// Link the action to the menu bar ui->menu_File->addAction(quitAction); ui->menu_File->addAction(aboutQtAction); ui->menuAbout->addAction(aboutQtAction);