【QT】新建QT工程(详细步骤)

新建QT工程

    • 1.方法
      • [(1)点击new project按钮,弹出对话框,新建即可,步骤如下:](#(1)点击new project按钮,弹出对话框,新建即可,步骤如下:)
      • [(2) 点击文件菜单,选择新建文件或者工程,后续步骤如上](#(2) 点击文件菜单,选择新建文件或者工程,后续步骤如上)
    • 2.QT工程文件介绍
      • [(1).pro文件 --》QT工程配置文件](#(1).pro文件 --》QT工程配置文件)
      • [(2)main.cpp --》QT工程主函数所在的源码](#(2)main.cpp --》QT工程主函数所在的源码)

1.方法

(1)点击new project按钮,弹出对话框,新建即可,步骤如下:



(2) 点击文件菜单,选择新建文件或者工程,后续步骤如上

2.QT工程文件介绍

(1).pro文件 --》QT工程配置文件

c 复制代码
QT       += core gui //添加要使用的QT库  core(核心库)  gui(图形用户交互库)

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets  //添加widgets窗口库

TARGET = firstqt  //生成的可执行程序的名字
TEMPLATE = app    //生成QT应用程序


SOURCES += main.cpp\
          mainwindow.cpp   //QT工程编译需要用到的源码

HEADERS  += mainwindow.h    //QT工程编译需要的头文件

FORMS    += mainwindow.ui   //QT工程中的界面文件

配置如下:

c 复制代码
QT       += core gui


greaterThan(QT_MAJOR_VERSION, 4): QT += widgets


CONFIG += c++11


# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS


# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# 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


SOURCES += \
    main.cpp \
    mainwindow.cpp


HEADERS += \
    mainwindow.h


FORMS += \
    mainwindow.ui


# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target


RESOURCES += \
    res.qrc

    

(2)main.cpp --》QT工程主函数所在的源码

cpp 复制代码
 int main(int argc, char *argv[])
{ 
    QApplication a(argc, argv);  //管理整个QT程序(管理QT的信号与槽,管理QT的事件响应)
    MainWindow w;       //创建了一个主窗口对象,叫做w
    w.show();           //显示主窗口
    return a.exec();    //进入事件循环,不断地刷新主窗口
}
相关推荐
用户8055336980311 小时前
不止三件套:QObject 属性系统全关键字与运行时反射!
c++·qt
xcyxiner12 小时前
DicomViewer (vcpkg Windows和ubuntu编译)7
qt
Quz5 天前
QML Hello World 入门示例
qt
xcyxiner8 天前
DicomViewer (dcmtk读取dcm文件)5
qt
xcyxiner9 天前
DicomViewer (后台线程处理文件)4
qt
xcyxiner9 天前
DicomViewer (添加模型类)3
qt
xcyxiner10 天前
DicomViewer (目录调整) 2
qt
xcyxiner10 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
LDR00612 天前
Type-C 快充全面升级!LDR6601 赋能个人护理便携电机,重塑剃须刀 / 理发器新体验
c语言·开发语言
雪碧聊技术12 天前
Tree.js是什么?一文讲透
开发语言·javascript·ecmascript