zoukankan      html  css  js  c++  java
  • QT 信号与槽关联的两种方式

    //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修饰
  • 相关阅读:
    [日料探店] 食一料理
    工地英语
    C++20协程解糖
    C++20协程解糖
    C++20协程解糖
    单表操作
    数据库查询语句罗列
    数据库简易介绍
    mysql的常用操作
    css基础
  • 原文地址:https://www.cnblogs.com/xuhongfei0021/p/10812762.html
Copyright © 2011-2022 走看看