Qt5简单分析之Qwidget

mywidget.h

#ifndef MYWIDGET_H
#define MYWIDGET_H

#include <QWidget>
// MyWidget类继承QWidget类
class MyWidget : public QWidget
{
    // 信号与槽的时候需要
    Q_OBJECT

public:
    // 构造函数
    MyWidget(QWidget *parent = 0);
    // 析构函数
    ~MyWidget();
};

#endif // MYWIDGET_H

main.cpp

#include "mywidget.h"
// 应用程序类
#include <QApplication>

int main(int argc, char *argv[])
{
    // 创建一个应用程序类对象
    QApplication a(argc, argv);
    // 创建一个MyWidget对象,该类继承QWidget类
    MyWidget w;
    // 显示窗口
    w.show();
    // 让程序一直执行等待用户操作(等待事件发生)
    a.exec();
    return 0;
}

mywidget.cpp

#include "mywidget.h"

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

MyWidget::~MyWidget()
{

}

QtTest.pro

#-------------------------------------------------
#
# Project created by QtCreator 2018-08-18T20:29:56
#
#-------------------------------------------------
#模块
QT       += core gui
#高于4版本,QT += widgets 为了兼容Qt4
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
#应用程序名称
TARGET = QtTest
#指定makefile类型 app
TEMPLATE = app

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

#源文件
SOURCES += main.cpp\
        mywidget.cpp
#头文件
HEADERS  += mywidget.h

猜你喜欢

转载自blog.csdn.net/qq2942713658/article/details/81812909
Qt5