初始qt
This commit is contained in:
Executable
+17
@@ -0,0 +1,17 @@
|
||||
#include "widget.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// 1. Qt 应用程序
|
||||
QApplication a(argc, argv);
|
||||
|
||||
// 2. 应用程序中显示的主窗口
|
||||
Widget w;
|
||||
w.show();
|
||||
|
||||
// 3. 启动 Qt 程序, 监听窗口的相关事件
|
||||
// 直到窗口关闭事件发生才退出
|
||||
return a.exec(); // a.exec 的目的是保持程序活着
|
||||
}
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
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 \
|
||||
widget.cpp
|
||||
|
||||
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
|
||||
Executable
+41
@@ -0,0 +1,41 @@
|
||||
#include "widget.h"
|
||||
#include <QApplication>
|
||||
#include <QPushButton>
|
||||
|
||||
Widget::Widget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
this->setWindowTitle("我是第一个小窗口");
|
||||
|
||||
// this -> resize(200,300);
|
||||
|
||||
this->setFixedSize(QSize(480, 320));
|
||||
|
||||
// 创建一个按钮
|
||||
// c++中创建类对象的两种方式:
|
||||
// 1) 类名 对象 (构造函数的)
|
||||
QPushButton *btn = new QPushButton("退出");
|
||||
btn->resize(100, 50); // 设置控件的大小
|
||||
btn->setParent(this); // 设置控件在哪一个窗口显示
|
||||
|
||||
btn->move(190, 135);
|
||||
|
||||
// connect(btn,&QPushButton::clicked,this,&QApplication::quit);
|
||||
connect(btn, &QPushButton::clicked, this, &QWidget::close);
|
||||
|
||||
QPushButton *btn2 = new QPushButton("2");
|
||||
btn2->resize(100, 50); // 设置控件的大小
|
||||
btn2->setParent(this); // 设置控件在哪一个窗口显示
|
||||
|
||||
btn2->move(190 + 100, 135);
|
||||
|
||||
QPushButton *btn3 = new QPushButton("3");
|
||||
btn3->resize(100, 50); // 设置控件的大小
|
||||
btn3->setParent(this); // 设置控件在哪一个窗口显示
|
||||
|
||||
btn3->move(190 + 200, 135);
|
||||
}
|
||||
|
||||
Widget::~Widget()
|
||||
{
|
||||
}
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
#ifndef WIDGET_H
|
||||
#define WIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class Widget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Widget(QWidget *parent = nullptr);
|
||||
~Widget();
|
||||
};
|
||||
#endif // WIDGET_H
|
||||
Reference in New Issue
Block a user