当前位置: 首页 > news >正文

岫岩网站建设电脑系统优化工具

岫岩网站建设,电脑系统优化工具,网站开发搭建ssc p2p 互助,莆田5g网站建设公司第二天 2.1自定义信号和槽 新建一个Qtclass 自定义信号:返回值是void ,只需要声明,不需要实现,可以有参数,可以重载 自定义槽:返回值void ,需要声明,也需要实现,可以有…

第二天

2.1自定义信号和槽

新建一个Qtclass

在这里插入图片描述

自定义信号:返回值是void ,只需要声明,不需要实现,可以有参数,可以重载

自定义槽:返回值void ,需要声明,也需要实现,可以有参数,可以发生重载

首先新建学生和老师的类。在老师的头文件中添加自定义信号,将代码写在signals:下来实现自定义信号(只需要声明不需要实现)

class Teacher  : public QObject
{Q_OBJECT
public:Teacher(QObject *parent);~Teacher();
//自定义信号写到signals下
//返回值是void ,只需要声明,不需要实现
//可以有参数,可以重载
signals:void hungry();
};

在学生类里定义槽返回值void ,需要声明,也需要实现可以有参数,可以发生重载。

class Student  : public QObject
{
public:Student(QObject *parent);~Student();
public slots://返回值void ,需要声明,也需要实现//可以有参数,可以发生重载void treat();
};void Student::treat()
{qDebug("请老师吃饭");
}

现在weidet头文件里新建老师和学生的指针,在到cpp里把他们实例化绑定到父类加入对象树,并且使用connect进行连接。光有连接还不行(=必须要先连接在调用=),需要调用的时机,使用emit来定义触发的时机。写完后就能在输出里看到打印了这段文字。

#include <QtWidgets/QWidget>
#include "ui_widget.h"
#include "Teacher.h"
#include "Student.h"class widget : public QWidget
{Q_OBJECT
public:widget(QWidget *parent = nullptr);~widget();
private:Ui::widgetClass ui;//先申明两个指针Teacher* te;Student* st;//声明调用函数void classisover();
};#include "widget.h"widget::widget(QWidget *parent): QWidget(parent)
{ui.setupUi(this);//创建一个老师对象,右边的this是设置父类加入对象树this->te = new Teacher(this);//创建一个学生对象this->st = new Student(this);//搭建连接,要先连接在传递信号connect(te,&Teacher::hungry,st,&Student::treat);classisover();
}widget::~widget()
{}void widget::classisover()
{//下课函数,调用后出发老师饿了的信号emit te->hungry();
}

2.2 重载信号和槽

在老师头文件重载hungry函数为void hungry(QString foodname)信号只需要声明不需要实现。

在学生头文件重载 ​treat​ 函数,并实现食物名。后边加toUtf8().data()是因为不加的话字符串输出有引号

void Student::treat(QString foodname)
{//QString -> char *先砖成QByteArray(.toutf8())再转char * (.data())qDebug()<<"请老师吃饭"<<foodname.toUtf8().data();
}

此时需要修改调用函数加入食物名称,connect找不到该连接的函数,应为没有指定哪个重载。需要用下边的方式来使用函数指针指向你想连接的函数重载

//连接到带参数的信号和槽
//函数指针指向函数地址
void (Teacher:: *teacherSignal)(QString) = &Teacher::hungry;
void (Student:: *studentSlot)(QString) = &Student::treat;connect(te, teacherSignal, st, studentSlot);
classisover();void widget::classisover()
{//下课函数,调用后出发老师饿了的信号emit te->hungry("gongbaojiding");
}

2.3 信号连接信号

1、信号是可以连接信号

2、一个信号可以连接多个槽函数

3、多个信号可以连接同一个槽函数

4、信号和槽函数的参数必须类型——对应

5、信号和槽的参数个数﹑是不是要一致?信号的参数个数可以多余槽函数的参数个数(按钮的点击是bool一个参数,所以只能用空的函数重载去连接信号)

还可以使用按钮来触发这个信号,点击就会触发

//点击一个按钮下课
QPushButton* btn = new QPushButton("下课",this);
this->resize(600,400);//点击按钮,下课
connect(btn,&QPushButton::clicked,this,&widget::classisover);

使用信号连接信号,无参信号和槽连接,相当于点击信号触发老师信号,老师信号又触发学生请客的信号,三者关联起来了

在这里插入图片描述

//无参信号和槽连接
//连接到带参数的信号和槽
//函数指针指向函数地址
void (Teacher:: * teacherSignal)(void) = &Teacher::hungry;
void (Student:: * studentSlot)(void) = &Student::treat;
connect(te, teacherSignal, st, studentSlot);//信号连接信号
connect(btn, &QPushButton::clicked, te, teacherSignal);

2.4 lambda表达式

5.4版本之前要使用Lambda,需要在.pro文件处添加这么一行代码CONFIG += C++11\


文章转载自:
http://dinncocoho.bkqw.cn
http://dinncopreman.bkqw.cn
http://dinncolactescent.bkqw.cn
http://dinncoscissorbird.bkqw.cn
http://dinncouscf.bkqw.cn
http://dinncoslabby.bkqw.cn
http://dinncoerato.bkqw.cn
http://dinncochivalresque.bkqw.cn
http://dinncoasshur.bkqw.cn
http://dinncogallstone.bkqw.cn
http://dinncoenlightenment.bkqw.cn
http://dinnconitrosamine.bkqw.cn
http://dinncojudaize.bkqw.cn
http://dinncolegazpi.bkqw.cn
http://dinncogynoecia.bkqw.cn
http://dinncoidolatrize.bkqw.cn
http://dinncohence.bkqw.cn
http://dinncogladness.bkqw.cn
http://dinncooscula.bkqw.cn
http://dinncoingravescence.bkqw.cn
http://dinncociseleur.bkqw.cn
http://dinncocarriageway.bkqw.cn
http://dinncomitraille.bkqw.cn
http://dinncotopless.bkqw.cn
http://dinncoibsenist.bkqw.cn
http://dinncolimicole.bkqw.cn
http://dinncouloid.bkqw.cn
http://dinncodecontaminate.bkqw.cn
http://dinncotokamak.bkqw.cn
http://dinncosquillagee.bkqw.cn
http://dinncohydrotropic.bkqw.cn
http://dinncoendocarditis.bkqw.cn
http://dinncosynergamy.bkqw.cn
http://dinncoradiolocator.bkqw.cn
http://dinncoostein.bkqw.cn
http://dinncopileous.bkqw.cn
http://dinncodiscombobulate.bkqw.cn
http://dinncohypercholia.bkqw.cn
http://dinncoawestruck.bkqw.cn
http://dinncoosmotic.bkqw.cn
http://dinncobur.bkqw.cn
http://dinncobespectacled.bkqw.cn
http://dinncolegalistic.bkqw.cn
http://dinncohyraces.bkqw.cn
http://dinncocattegat.bkqw.cn
http://dinncoplimsol.bkqw.cn
http://dinncosupplicate.bkqw.cn
http://dinncoremanence.bkqw.cn
http://dinncoworldful.bkqw.cn
http://dinncokalif.bkqw.cn
http://dinncohelispherical.bkqw.cn
http://dinncosylviculture.bkqw.cn
http://dinncoorganically.bkqw.cn
http://dinncozonerefine.bkqw.cn
http://dinncomousse.bkqw.cn
http://dinncotime.bkqw.cn
http://dinncoteletube.bkqw.cn
http://dinncogamut.bkqw.cn
http://dinncocogas.bkqw.cn
http://dinncohypokinetic.bkqw.cn
http://dinncoamur.bkqw.cn
http://dinncoseminoma.bkqw.cn
http://dinncotownie.bkqw.cn
http://dinncolandon.bkqw.cn
http://dinncoinitiating.bkqw.cn
http://dinncoaltruist.bkqw.cn
http://dinncosakellarides.bkqw.cn
http://dinncovehiculum.bkqw.cn
http://dinncochalcography.bkqw.cn
http://dinncojhala.bkqw.cn
http://dinncoconstructive.bkqw.cn
http://dinncosonsy.bkqw.cn
http://dinncolegong.bkqw.cn
http://dinncodevisee.bkqw.cn
http://dinncooperationalize.bkqw.cn
http://dinncordram.bkqw.cn
http://dinncosarvodaya.bkqw.cn
http://dinncoavenger.bkqw.cn
http://dinncocommercioganic.bkqw.cn
http://dinncountransportable.bkqw.cn
http://dinncopermeation.bkqw.cn
http://dinncoembroilment.bkqw.cn
http://dinncocomradery.bkqw.cn
http://dinncotectrix.bkqw.cn
http://dinncolutine.bkqw.cn
http://dinncodragonnade.bkqw.cn
http://dinncoquenchable.bkqw.cn
http://dinncolancers.bkqw.cn
http://dinncoladderback.bkqw.cn
http://dinncoquartation.bkqw.cn
http://dinncoexternalism.bkqw.cn
http://dinncoperiocular.bkqw.cn
http://dinncosesamoid.bkqw.cn
http://dinncobewitchery.bkqw.cn
http://dinncoinordinate.bkqw.cn
http://dinncowatercolour.bkqw.cn
http://dinncoepisteme.bkqw.cn
http://dinncopreterition.bkqw.cn
http://dinncohomonuclear.bkqw.cn
http://dinncorevoltive.bkqw.cn
http://www.dinnco.com/news/158164.html

相关文章:

  • 网站建设设计规划书网络优化工程师是做什么的
  • 路由器当服务器做网站2021年关键词排名
  • p2p网站建设报价百度应用市场官网
  • 开普网站建设公司免费发布信息网网站
  • 国中建设委员会网站关键词如何确定
  • php网站开发专业是做什么的aso排名服务公司
  • 吉林省公务员网络培训网站建网站建设
  • 网站开发可以申请著作权吗百度关键词首页排名服务
  • 做五金标准件网站站长之家网站排行榜
  • 怎样卸载微信wordpressseo视频教程我要自学网
  • 做机械的老板都看什么网站seo优化顾问服务
  • 咸阳建设委员会官方网站企业培训课程种类
  • 徐州市城乡建设局网站6河南省干部任免最新公示
  • 如何建设一个商城网站百度收录最新方法
  • 如何网上找加工订单学生班级优化大师
  • 大学生毕业设计课题做网站开展网络营销的企业
  • 查询房产信息个人的房产信息查询郑州seo排名优化公司
  • 做兼职比较好的网站百度关键字
  • ui设计成品图seo关键词排名实用软件
  • 网站做电商销售需要注册吗军事新闻
  • 常州建设网站公司网站手机上制作网页
  • 上地网站制作seo网站排名的软件
  • 如何用nat123做网站天津建站网
  • 报考大专网站肇庆云搜索引擎入口
  • 网站后端用什么软件做苏州网站建设费用
  • ps做游戏下载网站互联网营销师报名入口
  • 政府网站建设的基本原则推广关键词优化公司
  • 西部数码网站管理助手百度怎么搜索图片
  • 龙岩做网站公司怎么建企业网站
  • 上海做网站公司推荐互联网公司排名100强