avatar

Qt的框架

main.cpp

#include "widget.h"
#include <QApplication>
//QApplication应用程序类
//Qt头文件没有.h
//头文件和类名一样
int main(int argc, char *argv[])
{
//有且只有一个应用程序类对象
QApplication a(argc, argv);
//MyWidget继承Qwidget,QWidget是一个窗口类对象
//w是窗口
Widget w;
//窗口创建默认是隐藏的,需要认为显示
w.show();
//让程序一直执行,等待人为操作(等待事件的发生)
return a.exec();//a是应用程序对象
}

##.pro

#-------------------------------------------------
#
# Project created by QtCreator 2019-06-28T19:37:51
#
#-------------------------------------------------

#项目文件用“#”注释
#模块
QT += core gui
#高于4版本添加QT+=widgets,为了兼容4
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
#应用程序的名字
TARGET = untitled5
#指定makefile的类型,app/lib(库)
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as 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 you use 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

CONFIG += c++11
#源文件.cpp
SOURCES += \
main.cpp \
widget.cpp
#头文件.h
HEADERS += \
widget.h

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

##widget.h

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>

class Widget : public QWidget
{
Q_OBJECT//信号与槽需要

public:
Widget(QWidget *parent = 0);
~Widget();
};

#endif // WIDGET_H

##widget.cpp

#include "widget.h"

Widget::Widget(QWidget *parent)
: QWidget(parent)
{
}

Widget::~Widget()
{

}

Author: Michelle19l
Link: https://gitee.com/michelle19l/michelle19l/2019/08/31/Qt/Qt的框架/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
Donate
  • 微信
    微信
  • 支付寶
    支付寶