QT 编译过程了解:
#include <QApplication> //应用程序类
#include <QLabel> //标签类
#include <QLineEdit> //行编辑框类
#include <QPushButton> //按钮类
#include <QHBoxLayout> //水平布局类
#include <QVBoxLayout> //垂直布局类
#include <QWidget> //窗口类
int main(int argc, char *argv[])
{
QApplication a(argc,argv);
QLabel *InfoLabel = new QLabel;
QLabel *OpenLabel = new QLabel;
QLineEdit *cmdLineEdit = new QLineEdit;
QPushButton *commitButton = new QPushButton;
QPushButton *cancelButton = new QPushButton;
QPushButton *browseButton = new QPushButton;
InfoLabel->setText("please input the cmd: ");
OpenLabel->setText("open:");
commitButton->setText("commit");
cancelButton->setText("cancel");
browseButton->setText("browse");
QHBoxLayout *cmdlayout = new QHBoxLayout; //水平布局对象
cmdlayout->addWidget(OpenLabel);
cmdlayout->addWidget(cmdLineEdit);
QHBoxLayout *ButtonLayout = new QHBoxLayout;
ButtonLayout->addWidget(commitButton);
ButtonLayout->addWidget(cancelButton);
ButtonLayout->addWidget(browseButton);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(InfoLabel);
mainLayout->addLayout(cmdlayout);
mainLayout->addLayout(ButtonLayout);
QWidget w;
w.setLayout(mainLayout);
w.setWindowTitle("running");
w.show();
return a.exec(); //让程序一直运行,不结束,相当于while循环
}
配置环境变量:在Path中加入qt 编译器的路径;
进入到你编写的.cpp 文件目录下,执行 qmake -project 生成工程目录
生成 pro 工程,打开工程文件,修改 添加 QT += widgets gui
执行命令:qmake
生成,并打开 release 文件夹,打开 exe 执行文件。