首页 > 其他 > 详细

QT 信号与槽关联的两种方式

时间:2019-05-05 14:39:32      阅读:149      评论:0      收藏:0      [点我收藏+]
//1. 使用QT5灵活方式 可指定任意函数为槽函数,信号重载的辨别使用函数指针
    void (subwindow::*fun1)()=&subwindow::mysubsignal;
    void (subwindow::*fun2)(int,QString)=&subwindow::mysubsignal;


    connect(&b,&QPushButton::released,this,&testwidget::myslot);

    connect(&sub,fun1,this,&testwidget::myslot_others);
    connect(&sub,fun2,this,&testwidget::myslot_others2); //出现二义性 信号出现重载 这样需要函数指针

//2. 使用QT4的宏定义方式 

 connect(&sub,SIGNAL(mysubsignal()),this,SLOT(myslot_others()));
    connect(&sub,SIGNAL(mysubsignal(int,QString)),this,SLOT(myslot_others2(int,QString)));  //SIGNAL 不报错 相比于上边的方式 转换为字符串 槽函数得用SLOT 修饰
    
 //上述方式应当注意,若宏SIGNAL中的函数名写错的话编译器不报错, 另外槽函数的声明应使用SLOT修饰

 

QT 信号与槽关联的两种方式

原文:https://www.cnblogs.com/xuhongfei0021/p/10812762.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!