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

网站头部固定北京建设网官网证书

网站头部固定,北京建设网官网证书,seo搜索引擎优化平台,海南高端网站建设信号槽中的函数重载 QT4的方式QT5的方式函数指针重载函数QT5信号函数重载解决方案 总结 QT4的方式 Qt4中声明槽函数必须要使用 slots 关键字, 不能省略。 信号函数#xff1a; 槽函数#xff1a; mainwondow: cpp文件#xff1a; #include mainwindow.h… 信号槽中的函数重载 QT4的方式QT5的方式函数指针重载函数QT5信号函数重载解决方案 总结 QT4的方式 Qt4中声明槽函数必须要使用 slots 关键字, 不能省略。 信号函数 槽函数 mainwondow: cpp文件 #include mainwindow.h #include ui_mainwindow.h #include QDebugMainWindow::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 QDebugMainWindow::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); } 总结 Qt4的信号槽连接方式因为使用了宏函数, 宏函数对用户传递的信号槽不会做错误检测, 容易出bugQt5的信号槽连接方式, 传递的是信号槽函数的地址, 编译器会做错误检测, 减少了bug的产生当信号槽函数被重载之后, Qt4的信号槽连接方式不受影响当信号槽函数被重载之后, Qt5中需要给被重载的信号或者槽定义函数指针
http://www.yutouwan.com/news/220992/

相关文章:

  • 网站建设工作总结范文电子商务网页设计试题
  • 企业3合1网站建设价格南昌seo排名外包
  • 网站建设公司投诉电话室内设计网站配色app
  • dw做的简单的个人网站网盘wordpress里修改网页
  • 蒙牛网站建设方案网站收录差
  • 世界上有一个wordpress站点专业网站开发哪里有
  • 邯郸网站seo国外做化工产品的网站
  • 网站流量提供商江苏网站seo平台
  • 做仓单的网站在线制作手机网站
  • 网站需要什么费用深圳市住房和建设局官网平台
  • 中国做贸易的网站做网站公司哪家好
  • 大气金融php网站源码cn域名注册网站
  • 精品网站建设比较好seo好wordpress主题
  • wp网站做企业站好不好oa网站开发
  • asp个人网站模板肇庆建站模板源码
  • 个人网站内容有哪些内容免费的推广软件下载
  • 沈阳做公司网站的公司免费网站推广怎么做
  • 电子商务网站的作用有哪些wordpress app内
  • 循化网站建设公司汕头百姓网二手房出售
  • dw 做网站图片之间的链接珠海市建设工程造价协会网站
  • 推广联盟网站怎么做html模板框架
  • 怎么做业务网站qq交流群怎么升级会员
  • 做资源网站怎么赚钱做竞彩网站代理犯法么
  • 东莞定制网站开发seo职位描述
  • 怎么做网站教程视频中文html网站模板下载
  • 找合伙人做红木家具网站个人简历word可编辑免费
  • 城乡住房建设部网站造价师网产品开发设计流程
  • 如何免费建立官方网站wordpress 文章 自动生成标签
  • 企业为啥要做网站企业营销推广型网站建设
  • 用js做的网站代码吗买源码做网站