qt(2)__QT的信号与槽函数

connect()声明如下例,

connect(sender, SIGNAL(signal), receiver, SLOT(slot));

  • 一个信号可以连到多个槽函数
  • connect(slider, SIGNAL(valueChanged(int)),
            spinBox, SLOT(setValue(int)));
    connect(slider, SIGNAL(valueChanged(int)),
            this, SLOT(updateStatusBarIndicator(int)));
  • 多个信号可以连到单个槽函数
  • connect(lcd, SIGNAL(overflow()),
            this, SLOT(handleMathError()));
    connect(calculator, SIGNAL(divisionByZero()),
            this, SLOT(handleMathError()));
    
  • 一个信号还可以连到另一个信号
  • connect(lineEdit, SIGNAL(textChanged(const QString &)),
            this, SIGNAL(updateRecord(const QString &)));
    
  • 信号的连接可以移除
  • disconnect(lcd, SIGNAL(overflow()),
               this, SLOT(handleMathError()));
    

信号与槽连接的注意点:

信号与槽必须有相同的参数类型与顺序,如

connect(ftp, SIGNAL(rawCommandReply(int, const QString &)),
        this, SLOT(processReply(int, const QString &)));

有一个例外,如果信号有比槽函数多的参数,按顺序,多余的参数,将被忽略

connect(ftp, SIGNAL(rawCommandReply(int, const QString &)),
         this, SLOT(checkErrorCode(int)));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值