新建QT工程
- 1.方法
- (1)点击new project按钮,弹出对话框,新建即可,步骤如下:
- (2) 点击文件菜单,选择新建文件或者工程,后续步骤如上
- 2.QT工程文件介绍
- (1).pro文件 --》QT工程配置文件
- (2)main.cpp --》QT工程主函数所在的源码
1.方法
(1)点击new project按钮,弹出对话框,新建即可,步骤如下:
(2) 点击文件菜单,选择新建文件或者工程,后续步骤如上
2.QT工程文件介绍
(1).pro文件 --》QT工程配置文件
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工程中的界面文件
配置如下:
QT += core guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsCONFIG += 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.0SOURCES += \main.cpp \mainwindow.cppHEADERS += \mainwindow.hFORMS += \mainwindow.ui# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += targetRESOURCES += \res.qrc
(2)main.cpp --》QT工程主函数所在的源码
int main(int argc, char *argv[])
{ QApplication a(argc, argv); //管理整个QT程序(管理QT的信号与槽,管理QT的事件响应)MainWindow w; //创建了一个主窗口对象,叫做ww.show(); //显示主窗口return a.exec(); //进入事件循环,不断地刷新主窗口
}