一、修改环境变量
二、生成工程文件
1、qt-cmd进入工程目录
2、 qmake -project 生成工程文件
3、修改工程文件,最后一行添加:
QT += gui widgets
三、生成makefile
执行命令
qmake
四、编译工程
mingw32-make
注:如果找不到命令,需要添加环境变量,mingw32-make.exe在Qt5.8.0\Tools\mingw530_32\bin目录下
#include <QApplication>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QHBoxLayout> //水平布局
#include <QVBoxLayout> //垂直布局
#include <QWidget>
int main(int argc,char *argv[])
{
QApplication app(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("input cmd:");
openLabel->setText("open");
commitButton->setText("cancel");
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.show();
w.setWindowTitle("running");
return app.exec();
}