1.基础
1. 安装最后一个非在线版本 5.14,
没有的话联系我
新建一个.cpp文件
#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");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.show();return app.exec();
}
2.添加环境变量
命令行界面:
生成工程文件
1)qmake -project
进入工程目录,也就是cpp所在文件夹,执行qmake -project
下文中的pro后缀代表project
注意此时需要打开该文件添加行QT+=widgets gui
######################################################################
# Automatically generated by qmake (3.1) Mon Sep 16 08:56:09 2024
######################################################################TEMPLATE = app
TARGET = qt1
INCLUDEPATH += .# You can make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# Please consult the documentation of the deprecated API in order to know
# how to port your code away from it.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0# Input
SOURCES += qmake.cppQT+=widgets gui
2)qmake
再执行 qmake,每次修改文件之后可以直接执行qmake
3)mingw32-make
因为在windows环境,再执行mingw32-make,如果是linux环境直接执行make
QT+=gui widgets
release文件夹就会出现,也就可以了