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

今天中国疫情最新消息黑帽seo技术论坛

今天中国疫情最新消息,黑帽seo技术论坛,建网站 多少钱,网站建设怎么骗人信号槽中的函数重载 QT4的方式QT5的方式函数指针重载函数QT5信号函数重载解决方案 总结 QT4的方式 Qt4中声明槽函数必须要使用 slots 关键字, 不能省略。 信号函数: 槽函数: mainwondow: cpp文件: #include "mainwindow.h"…

信号槽中的函数重载

  • QT4的方式
  • QT5的方式
    • 函数指针重载函数
    • QT5信号函数重载
      • 解决方案
  • 总结

QT4的方式

Qt4中声明槽函数必须要使用 slots 关键字, 不能省略。

信号函数:
在这里插入图片描述
槽函数:
在这里插入图片描述
在这里插入图片描述
mainwondow:
在这里插入图片描述
在这里插入图片描述
cpp文件:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QDebug"MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{ui->setupUi(this);tom = new me(this);teacher = new myteacher(this);//connect(ui->pushButtonqt4,&QPushButton::clicked,this,&MainWindow::sendMsg);//qt4的连接方式connect(ui->pushButtonqt4,SIGNAL(clicked()),this,SLOT(sendMsg()) );connect(tom,SIGNAL(sendMsg()),teacher,SLOT(receiveMsg()));connect(tom,SIGNAL(sendMsg(QString )),teacher,SLOT(receiveMsg(QString )));//qt5的连接方式}MainWindow::~MainWindow()
{delete ui;
}void MainWindow::sendMsg()
{qDebug()<<"调用一次";//tom->sendMsg();QString s =" hello";tom->sendMsg(s);
}

调用有参的信号函数:
在这里插入图片描述
调用无参的信号函数:

在这里插入图片描述

在这里插入图片描述

QT5的方式

函数指针重载函数

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

QT5信号函数重载

信号函数和槽函数和之前QT4中是一样的。
信号函数;
在这里插入图片描述
槽函数:
在这里插入图片描述
在这里插入图片描述
关联方式:
在这里插入图片描述

报错如下:E:\Code\Qt\mySignalAndSlot3\mainwindow.cpp:20: error: no matching function for call to 'MainWindow::connect(me*&, <unresolved overloaded function type>, myteacher*&, <unresolved overloaded function type>)' connect(tom,&me::sendMsg,teacher,&myteacher::receiveMsg); ^

信号和槽都是通过函数名去关联函数的地址, 但是这个同名函数对应两块不同的地址, 一个带参, 一个不带参, 因此编译器就不知道去关联哪块地址了, 所以如果我们在这种时候通过以上方式进行信号槽连接, 编译器就会报错。

解决方案

可以通过定义函数指针的方式指定出函数的具体参数,这样就可以确定函数的具体地址了。
定义函数指针指向重载的某个信号或者槽函数,在connect()函数中将函数指针名字作为实参就可以了。

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QDebug"MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{ui->setupUi(this);tom = new me(this);teacher = new myteacher(this);//connect(ui->pushButtonqt4,&QPushButton::clicked,this,&MainWindow::sendMsg);//qt4的连接方式
//    connect(ui->pushButtonqt4,SIGNAL(clicked()),this,SLOT(sendMsg()) );
//    connect(tom,SIGNAL(sendMsg()),teacher,SLOT(receiveMsg()));
//    connect(tom,SIGNAL(sendMsg(QString )),teacher,SLOT(receiveMsg(QString )));//qt5的连接方式//函数指针void (me::*sendMsg1)() ;void (me::*sendMsg2)(QString s);void (myteacher::*receiveMsg1)();void (myteacher::*receiveMsg2)(QString s);sendMsg1 = &me::sendMsg;sendMsg2 = &me::sendMsg;receiveMsg1 = &myteacher::receiveMsg;receiveMsg2 = &myteacher::receiveMsg;connect(ui->pushButtonqt4,&QPushButton::clicked,this,&MainWindow::sendMsg);//connect(tom,&me::sendMsg,teacher,&myteacher::receiveMsg);//connect(tom,&me::sendMsg,teacher,&myteacher::receiveMsg);connect(tom,sendMsg1,teacher,receiveMsg1);connect(tom,sendMsg2,teacher,receiveMsg2);}MainWindow::~MainWindow()
{delete ui;
}void MainWindow::sendMsg()
{qDebug()<<"调用一次";tom->sendMsg();QString s =" hello";tom->sendMsg(s);
}

在这里插入图片描述

总结

  1. Qt4的信号槽连接方式因为使用了宏函数, 宏函数对用户传递的信号槽不会做错误检测, 容易出bug
  2. Qt5的信号槽连接方式, 传递的是信号槽函数的地址, 编译器会做错误检测, 减少了bug的产生
  3. 当信号槽函数被重载之后, Qt4的信号槽连接方式不受影响
  4. 当信号槽函数被重载之后, Qt5中需要给被重载的信号或者槽定义函数指针
http://www.yidumall.com/news/19929.html

相关文章:

  • 厦门 外贸商城网站建设网站优化排名易下拉系统
  • 郑州网站推广排名公司太仓网站制作
  • 做网站用动易siteweaver cms还是phpcms淄博信息港聊天室网址
  • 阳泉购物网站开发设计网店代运营可靠吗
  • 自己的电脑做服务区 网站典型的口碑营销案例
  • 网站建设有必要做手机端吗东莞商城网站建设
  • 小程序开发平台哪家服务好北京seo推广外包
  • 搜索引擎网站排名官方百度
  • 上海哪家公司做网站比较好个人博客网站模板
  • 滨州正规网站建设哪家好百度文库个人登录入口
  • 技术支持 嘉兴网站建设厦门网站建设公司名单
  • 西安有什么好玩的地方轻松seo优化排名
  • 免费的小网站百度经验发布平台
  • 3如何做网站推广搜狗站长平台主动提交
  • 白银做网站网站优化方案怎么写
  • 网站防采集如何建立一个自己的网站?
  • 手机模版网站价格微信seo是什么意思
  • 网站 日历插件网站数据统计工具
  • 音乐网站开发文档全网营销平台
  • 网站发送邮件功能seo学徒
  • 惠州做公司网站做谷歌推广比较好的公司
  • 哪个网站专题做的好免费建立个人网站
  • 北京市住房城乡建设委官方网站做关键词优化
  • wordpress自适应博客主题郑州seo关键词排名优化
  • 做网站的宽和高有限制吗广告营销包括哪些方面
  • 一个网站为什么做的不好看买域名
  • 做电商网站价钱深圳最新疫情
  • 日本巨乳做视频网站东莞关键词排名提升
  • 怎么判断代运营是真是假seo确定关键词
  • 做粘土的网站市场营销策划方案3000字