[菜鸡学QT笔记①]QT的编译过程

---本人没有十分系统学习过C++,该文章仅为学习笔记,没有干货

课程视频地址:QT快速入门 | 最简单最简洁的QT入门教程 | 嵌入式UI_哔哩哔哩_bilibili

目的:了解QT的编译过程,以后开发直接用QTCreator

1. 新建一个全英文的文件路径存放工程

2. 新建一个记事本,把后缀改为.cpp

3. 导入头文件

#include <QApplication>

QApplication 类管理图形用户界面应用程序的控制流和主要设置。 可以说 QApplication是Qt的整个后台管理的命脉。

它包含主事件循环,在其中来自窗口系统和其它资源的所有事件被处理和调度。它也处理应用程序的初始化和结束,并且提供对话管理。它也处理绝大多数系统范围和应用程序范围的设置。

4. 编写主函数

int main(int argc,char *argv[])
{

    return app.exec();
}

app.exec()的存在使软件不会闪退 ,app.exec()的含义是最后一个窗口关闭后软件才停止。

5. 添加各种类的头文件

#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类新建一个infoLabel对象
    QLabel *openLabel = new QLabel;    //QLabel类新建一个openLabel对象,下面同理
    QLineEdit *cmdLineEdit = new QLineEdit;
    QPushButton *commitButton = new QPushButton;
    QPushButton *cancelButton = new QPushButton;
    QPushButton *browseButton = new QPushButton;

    infoLabel->setText("input cmd:"); //setText编辑文本
    openLabel->setText("open");
    commitButton->setText("commit");
    cancelButton->setText("cancel");
    browseButton->setText("browse");

    QHBoxLayout *cmdLayout = new QHBoxLayout;//水平布局对象
    cmdLayout->addWidget(openLabel); //在布局中添加对象用addWidget
    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);//布局里面添加布局用addLayout
    mainLayout->addLayout(buttonLayout);

    QWidget w;//生成一个窗口
    w.setLayout(mainLayout);//设置窗口布局
    w.show();//必须添加这一句才能显示
    w.setWindowTitle("Running");//修改窗口名字

    return app.exec();
}

6. 保存后 ,打开QT命令行

7. 命令行中跳转至工程文件路径,输入qmake -project,生成工程文件

8. 输入 qmake 。qmake工具就是Qt公司制造出来,用来生成Qt 专用makefile文件,这种makefile文件就能自动智能调用moc和uic对源程序进行预处理和编译。qmake当然必须也是跨平台的,跟cmake一样能对应各种平台生成对应makefile文件。

 9. 编译文件,输入mingw32-make

 

 无报错,.exe程序正常运行

------end------

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值