QT(.cpp文件 至 应用程序)

1,首先在某盘(F盘)创建一个.cpp文件 生成一个如下图的应用程序
在这里插入图片描述

#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 *cancelBotton = new QPushButton;
	QPushButton *browseButton = new QPushButton;
	
	infoLabel->setText("input your cmd ..");
	openLabel->setText("open");
	commitButton->setText("commit");
	cancelBotton->setText("cancel");
	browseButton->setText("browse");
	
	QHBoxLayout *cmdLayout = new QHBoxLayout;			//水平布局对象
	cmdLayout->addWidget(openLabel);
	cmdLayout->addWidget(cmdLineEdit);
	
	QHBoxLayout *buttonLayout = new QHBoxLayout;
	buttonLayout->addWidget(commitButton);
	buttonLayout->addWidget(cancelBotton);
	buttonLayout->addWidget(browseButton);
	
	QVBoxLayout *mainLayout = new QVBoxLayout;			//全局的垂直布局
	mainLayout->addWidget(infoLabel);
	mainLayout->addLayout(cmdLayout);						//注意是addLayout() 在已经水平的一个组合
	mainLayout->addLayout(buttonLayout);
	
	QWidget *w = new QWidget;
	w->setLayout(mainLayout);
	w->show();
	
	return app.exec();
}

2,打开Qt的 命令提示符
(1),f: //进入F盘
(2),cd 路径 //cd F:\QMAKE\qmake
(3),qmake -project //生成工程项目
(4),用记事本打开 qmake.pro 添加内容 QT += widgets gui
(5),qmake //生成makefile 文件
(6),mingw32-make //编译生成若干个文件 找到release文件夹 点击应用程序即可

若计算机属性中的高级系统设置内-> 高级 ->环境变量(系统变量和用户变量)内的pash路径 内没有QT安装的路径,则需要-> 新建 -> 添加 将QT路径添加进去就可以了

猜你喜欢

转载自blog.csdn.net/qq_41915323/article/details/88919244