使用mingw64 编译 QT开发流程

1. 安装QT5

QT5.12.12

安装时选择mingw的开发包

2. 使用qtdesigner 进行ui设计 生成ui文件

3. 将ui文件转换为.h 文件

uic mywindow.ui -o ui_mywindow.h

代码中指向生成的 UI 对象的地方 要改成这个Form
在这里插入图片描述

4. 编译

创建mainwindow.cpp

#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Form)  // 指向生成的 UI 对象
{
    ui->setupUi(this);  // 设置 UI
    connect(ui->pushButton, &QPushButton::clicked, this, &MainWindow::on_pushButton_clicked);  // 连接按钮的点击事件到槽函数
}

MainWindow::~MainWindow()
{
    delete ui;  // 释放 UI 对象
}

void MainWindow::on_pushButton_clicked()
{
	
}

创建mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "ui_mainwindow.h"  // 包含生成的 UI 文件

#include <QMainWindow>
class MainWindow : public QMainWindow
{
    Q_OBJECT  // 使用 Qt 的信号和槽机制需要这个宏

public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private:
    Ui::Form *ui;  // 指向生成的 UI 对象

private slots:
    void on_pushButton_clicked();  // 当按钮被点击时调用的槽函数
};

#endif // MAINWINDOW_H

创建main.cpp

#include <QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}

5. 部署

  1. 需要将D:\5.12.12\mingw73_64\bin里面用到的dll 放入程序目录
  2. 需要将用到的plugins 放入目录中
    比如platforms 缺失等
    在这里插入图片描述
  • 6
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

图像处理大大大大大牛啊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值