#include "mymainwindow.h"
#include "ui_mymainwindow.h"
//#include <QMenuBar> //使用前向声明,不使用头文件包含的形式,主要是为了编译更快
class QMenuBar;//类的前向声明
myMainWindow::myMainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::myMainWindow)
{
ui->setupUi(this);
openAction = new QAction(tr("&open"),this);
openAction->setShortcut(QKeySequence::Open);//动作的快捷键;比如:open快捷键 Ctrl+O(Qt的QKeySequence定义的)
openAction->setStatusTip(tr("open a file"));//添加状态栏的提示语句
file = menuBar()->addMenu(tr("&File"));
file->addAction(openAction);
toolBar = addToolBar(tr("&File"));
toolBar->addAction(openAction);
}
myMainWindow::~myMainWindow()
{
delete ui;
}
运行之后,如图:
转载于:https://blog.51cto.com/11917685/1892012