#include "widget.h"
#include "ui_widget.h"
#include "qpushbutton.h"
//Teacher 类
//Student 类
//
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
//创建老师对象
this->TE = new Teacher(this);
//创建学生对象
this->ST = new Student(this);
//连接,老师饿了,学生请客
// connect(TE,&Teacher::hungry,ST,&Student::treat);
// //调用下课函数
// ClassOver();
//当有重载时,存在二义性。
//连接带参数的,信号和槽
//指针->地址
//函数指针->函数指针
void(Teacher::*teacherSignal)(QString) = &Teacher::hungry;
void(Student::*studentSlot)(QString) = &Student::treat;
connect(TE,teacherSignal,ST,studentSlot);
//ClassOver();
//点击下课按钮进行响应
QPushButton * btn = new QPushButton("下课",this);
resize(600,400);
//信号发送者 发送的信号(函数地址)信号接受者 处理的槽函数(地址)
//connect(btn,&QPushButton::clicked,this,&Widget::ClassOver);
//无参信号和槽 按钮只可以连接无参的函数
void(Teacher::*teacherSignal2)(void) = &Teacher::hungry;
void(Student::*studentSlot2)(void) = &Student::treat;
connect(TE,teacherSignal2,ST,studentSlot2);
//信号连接信号
connect(btn,&QPushButton::clicked,TE,teacherSignal2);
//拓展
// 1.信号是可以连接信号的
// 2.一个信号可以连接多个槽函数
// 3.多个信号可以连接同一个槽函数
// 4.信号和槽函数的参数必须类型一一对应
// 5.信号的参数个数,可以多于槽函数的参数个数(例:按钮参数是bool,老师饿了对应无参可以成功,对应有参时失败)
//qT4版本以前信号和槽连接方式
//利用Qt4信号槽 连接无参版本
//QT4版本 底层SIGNAL("hungry") SLOT("treat")以字符串进行检测,没有参数检测
//connect(TE,SIGNAL(hungry()),ST,SLOT(treat(QString)));//不符合标准
//Qt4优点,参数直观,缺点,类型不做检测
QPushButton *btn2 = new QPushButton("关闭",this);
btn2->move(100,200);
connect(btn2,QPushButton::clicked,this,[=](){
btn2->setText("成功");
//this->close();
});
}
void Widget::ClassOver()
{
//下课函数,调用后触发老师饿了的信号,
//自定义信号--触发的关键字emit
//emit TE->hungry();
emit TE->hungry("宫保鸡丁");
}
Widget::~Widget()
{
delete ui;
}
没有合适的资源?快使用搜索试试~ 我知道了~
SignalsAndSlots.zip
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共10个文件
cpp:4个
h:3个
ui:1个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
需积分: 1 0 下载量 199 浏览量
2022-07-14
20:22:59
上传
评论
收藏 7KB ZIP 举报
温馨提示
SignalsAndSlots.zip
资源详情
资源评论
资源推荐
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 10 条
- 1
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![thumb](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![avatar](https://profile-avatar.csdnimg.cn/6d27044d68e044d7b465139e3c0d08fc_m0_55986434.jpg!1)
LCH南安
- 粉丝: 102
- 资源: 10
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
- 数据库管理工具:dbeaver-ce-23.2.2-stable.x86-64.rpm
- 数据库管理工具:dbeaver-ce-23.2.2-macos-x86-64.dmg
- 数据库管理工具:dbeaver-ce-23.2.2-macos-aarch64.dmg
- 数据库管理工具:dbeaver-ce-23.1.5-stable.x86-64.rpm
- 以下是一些适用于英语六级作文的万能句型模板,涵盖了引言、正文和结论部分的各类表达方式.docx
- MATLAB中的非线性规划
- 进行C语言面试资格确认是招聘过程中一个重要的步骤,目的是确保候选人具备足够的C语言编程能力和知识.docx
- Java 轻量级的集群负载均衡设计
- 纹身师个人网站模板.jpg
- 在C语言中,连接两个字符串(即将一个字符串附加到另一个字符串的末尾)通常可以使用标准库中的 `strcat` 函数.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)
评论0