** Form generated from reading UI file 'mainwindow.ui'
**
** Created: Mon Dec 2 14:42:57 2013
** by: Qt User Interface Compiler version 4.7.4
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_MAINWINDOW_H
#define UI_MAINWINDOW_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QHeaderView>
#include <QtGui/QMainWindow>
#include <QtGui/QMenu>
#include <QtGui/QMenuBar>
#include <QtGui/QStatusBar>
#include <QtGui/QTextEdit>
#include <QtGui/QToolBar>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class Ui_MainWindow
{
public:
QAction *actionNew;
QAction *actionOpen;
QAction *actionClose;
QAction *actionSave;
QAction *actionSaveAs;
QAction *actionQuit;
QAction *actionUndo;
QAction *actionCut;
QAction *actionCopy;
QAction *actionPaste;
QAction *actionSelectAll;
QAction *actionSearchFile;
QWidget *centralwidget;
QTextEdit *textEdit;
QStatusBar *statusbar;
QMenuBar *menuBar;
QMenu *menuFile;
QMenu *menuEdit;
QMenu *menuTool;
QToolBar *FileToolBar;
QToolBar *EditToolBar;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(800, 600);
actionNew = new QAction(MainWindow);
actionNew->setObjectName(QString::fromUtf8("actionNew"));
actionOpen = new QAction(MainWindow);
actionOpen->setObjectName(QString::fromUtf8("actionOpen"));
actionClose = new QAction(MainWindow);
actionClose->setObjectName(QString::fromUtf8("actionClose"));
actionSave = new QAction(MainWindow);
actionSave->setObjectName(QString::fromUtf8("actionSave"));
actionSaveAs = new QAction(MainWindow);
actionSaveAs->setObjectName(QString::fromUtf8("actionSaveAs"));
actionQuit = new QAction(MainWindow);
actionQuit->setObjectName(QString::fromUtf8("actionQuit"));
actionUndo = new QAction(MainWindow);
actionUndo->setObjectName(QString::fromUtf8("actionUndo"));
actionCut = new QAction(MainWindow);
actionCut->setObjectName(QString::fromUtf8("actionCut"));
actionCopy = new QAction(MainWindow);
actionCopy->setObjectName(QString::fromUtf8("actionCopy"));
actionPaste = new QAction(MainWindow);
actionPaste->setObjectName(QString::fromUtf8("actionPaste"));
actionSelectAll = new QAction(MainWindow);
actionSelectAll->setObjectName(QString::fromUtf8("actionSelectAll"));
actionSearchFile = new QAction(MainWindow);
actionSearchFile->setObjectName(QString::fromUtf8("actionSearchFile"));
centralwidget = new QWidget(MainWindow);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
textEdit = new QTextEdit(centralwidget);
textEdit->setObjectName(QString::fromUtf8("textEdit"));
textEdit->setGeometry(QRect(0, 10, 711, 491));
MainWindow->setCentralWidget(centralwidget);
statusbar = new QStatusBar(MainWindow);
statusbar->setObjectName(QString::fromUtf8("statusbar"));
MainWindow->setStatusBar(statusbar);
menuBar = new QMenuBar(MainWindow);
menuBar->setObjectName(QString::fromUtf8("menuBar"));
menuBar->setGeometry(QRect(0, 0, 800, 28));
menuFile = new QMenu(menuBar);
menuFile->setObjectName(QString::fromUtf8("menuFile"));
menuEdit = new QMenu(menuBar);
menuEdit->setObjectName(QString::fromUtf8("menuEdit"));
menuTool = new QMenu(menuBar);
menuTool->setObjectName(QString::fromUtf8("menuTool"));
MainWindow->setMenuBar(menuBar);
FileToolBar = new QToolBar(MainWindow);
FileToolBar->setObjectName(QString::fromUtf8("FileToolBar"));
MainWindow->addToolBar(Qt::TopToolBarArea, FileToolBar);
EditToolBar = new QToolBar(MainWindow);
EditToolBar->setObjectName(QString::fromUtf8("EditToolBar"));
MainWindow->addToolBar(Qt::TopToolBarArea, EditToolBar);
menuBar->addAction(menuFile->menuAction());
menuBar->addAction(menuEdit->menuAction());
menuBar->addAction(menuTool->menuAction());
menuFile->addAction(actionNew);
menuFile->addAction(actionOpen);
menuFile->addAction(actionClose);
menuFile->addAction(actionSave);
menuFile->addAction(actionSaveAs);
menuFile->addAction(actionQuit);
menuEdit->addAction(actionUndo);
menuEdit->addAction(actionCut);
menuEdit->addAction(actionCopy);
menuEdit->addAction(actionPaste);
menuEdit->addAction(actionSelectAll);
menuTool->addAction(actionSearchFile);
retranslateUi(MainWindow);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8));
actionNew->setText(QApplication::translate("MainWindow", "\346\226\260\345\273\272", 0, QApplication::UnicodeUTF8));
actionOpen->setText(QApplication::translate("MainWindow", "\346\211\223\345\274\200", 0, QApplication::UnicodeUTF8));
actionClose->setText(QApplication::translate("MainWindow", "\345\205\263\351\227\255", 0, QApplication::UnicodeUTF8));
actionSave->setText(QApplication::translate("MainWindow", "\344\277\235\345\255\230", 0, QApplication::UnicodeUTF8));
actionSaveAs->setText(QApplication::translate("MainWindow", "\345\217\246\345\255\230\344\270\272", 0, QApplication::UnicodeUTF8));
actionQuit->setText(QApplication::translate("MainWindow", "\351\200\200\345\207\272", 0, QApplication::UnicodeUTF8));
actionUndo->setText(QApplication::translate("MainWindow", "\346\222\244\351\224\200", 0, QApplication::UnicodeUTF8));
actionCut->setText(QApplication::translate("MainWindow", "\345\211\252\345\210\207", 0, QApplication::UnicodeUTF8));
actionCopy->setText(QApplication::translate("MainWindow", "\345\244\215\345\210\266", 0, QApplication::UnicodeUTF8));
actionPaste->setText(QApplication::translate("MainWindow", "\347\262\230\345\270\226", 0, QApplication::UnicodeUTF8));
actionSelectAll->setText(QApplication::translate("MainWindow", "\345\205\250\351\200\211", 0, QApplication::UnicodeUTF8));
actionSearchFile->setText(QApplication::translate("MainWindow", "\346\237\245\346\211\276\346\226\207\344\273\266", 0, QApplication::UnicodeUTF8));
menuFile->setTitle(QApplication::translate("MainWindow", "\346\226\207\344\273\266", 0, QApplication::UnicodeUTF8));
menuEdit->setTitle(QApplication::translate("MainWindow", "\347\274\226\350\276\221", 0, QApplication::UnicodeUTF8));
menuTool->setTitle(QApplication::translate("MainWindow", "\345\267\245\345\205\267", 0, QApplication::UnicodeUTF8));
FileToolBar->setWindowTitle(QApplication::translate("MainWindow", "\346\226\260\345\273\272", 0, QApplication::UnicodeUTF8));
EditToolBar->setWindowTitle(QApplication::translate("MainWindow", "toolBar", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_MAINWINDOW_H
以上是由ui文件直接生成的.h文件,其中红色的部分就是我们生成的可以用的类,类名为MainWindow,命名空间为Ui,
接着我们新建一个类然后从此UI类中继承
#include <QApplication>
#include <QMainWindow>
#include <QWidget>
#include "ui_mainwindow.h"
//class Win : public QMainWindow,public Ui::MainWindow
class Win : public Ui::MainWindow,public QMainWindow
{
public:
Win(QMainWindow* parent = 0):QMainWindow(parent)/
{
setupUi(this);
}
};
//注意这边的父类要与 刚才生成的.h文件中 void setupUi(QMainWindow *MainWindow)对应
注意有的父类可能是QDialog,QWidget,可能不同,我有一次就是想当然认为是QWidget,结果出错
int main(int argc,char** argv)
{
QApplication app(argc,argv);
Win w;
w.show();
return app.exec();
}
这样qmake -project ;qmake;make就生成我们的程序了