创建框架
1.单击+New;
2.选择应用,然后选择第一个Qt窗体应用,选择下方choose;
3.①Location:更改项目名称(不能是中文),创建路径并勾选项目路径,同样不能有中文;
②Build System:默认;
③Details:第一次创建选择第二个作为基类,取消勾选;
④Translation:默认;
⑤Kits:
⑥Summary:默认;
内容介绍
创建完成之后会有默认生成的一些内容:
pro项目文件、头文件夹、源文件夹
主函数main.cpp:
#include "mywidget.h"
#include int main(int argc, char *argv[])
{QApplication a(argc, argv);MyWidget w;w.show();return a.exec();
}
头文件mywidget.h:
#ifndef MYWIDGET_H
#define MYWIDGET_H#include class MyWidget : public QWidget
{Q_OBJECTpublic:MyWidget(QWidget *parent = nullptr);~MyWidget();
};
#endif
pro项目文件:
QT += core gui#高于4版本,添加QT += widgets,为了兼容Qt4
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = FX
TEMPLATE = appCONFIG += 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 \mywidget.cpp
HEADERS += \mywidget.h# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target