QT-学习经验总结

pro工程文件

# QT包含的模块
QT       += core gui

# >=4,包含widgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
main.cpp \
mainwindow.cpp

HEADERS += \
mainwindow.h

FORMS += \
mainwindow.ui

# 目标,生成EXE的名字
TARGET = asd

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

QPushButton

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <qpushbutton.h>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)       // 初始化列表
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QPushButton * b = new QPushButton;  // 新建按钮的第一种方法
    //b->show();            // 独立顶层显示
    b->setParent(this);     // 设置父窗口
    b->setText("asdasd");   // 设置按钮的标签
    b->resize(20, 20);      // 设置按钮的大小
    QPushButton * c = new QPushButton("zxczxc", this);  // 新建按钮的第二种方法
    c->move(100, 100);              // 移动按钮的位置
    this->resize(300, 200);         // 设置窗口大小
    this->setWindowTitle("AAA");    // 设置窗口的名字
    this->setFixedSize(300, 600);   // 设置窗口固定大小
}

MainWindow::~MainWindow()
{
    delete ui;
}

信号和槽函数使用注意

// 1.信号可以连接信号
// 2.一个信号可以连接多个槽函数
// 3.多个信号可以连接一个槽函数
// 4.信号和槽函数的参数类型必须一一对应
// 5.信号和槽函数的参数的个数必须一一对应
// ,信号参数个数可以多于槽函数参数个数

Lambda表达式

空:没有参数
= :值传递,所有局部变量
& :引用传递,所有局部变量

posted @ 2022-03-27 14:22  starc的miao  阅读(101)  评论(0)    收藏  举报