插槽可以接受的自变量少于信号提供的自变量,怎么办? -Qt [英] A slot can take less arguments than provided by the signal, HOW? - Qt

查看:63
本文介绍了插槽可以接受的自变量少于信号提供的自变量,怎么办? -Qt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个信号,其声明是:

I have a signal which its declaration is:

void removed(int sPI, int sWID , int ePI, int eWID);

我想将它两次连接到插槽,首先需要sPI和sWID参数,而其他插槽需要ePI和eWID.插槽声明为:

I want to connect it to a slots twice, first needs sPI and sWID arguments and other slot needs ePI and eWID. The slot declaration is:

void disconnect(int i, int wID = 0);

(我希望当remove()发出时,断开连接(sPI,sWID)并断开连接(ePI,eWID))

( I want when removed() emits, disconnect(sPI, sWID) and also disconnect(ePI, eWID) )

请帮助我编写QObject :: connect()语句. 谢谢.

Please help me in writing QObject::connect() statement. Thanks.

推荐答案

对于第一个"disconnect(sPI,sWID)",只需执行以下操作:

For the first, "disconnect(sPI, sWID)", just do:

connect(x, SIGNAL(removed(int,int,int,int)), y, SLOT(disconnect(int,int)));

第三个参数和第四个参数将被忽略,而前两个参数将被称为断开连接.

The third and forth argument will just be ignored and disconnect will be called with the first two.

第二个连接"disconnect(ePI,eWID)"是不可能的.您需要一个连接到remove()的中间插槽:

The second connect, "disconnect(ePI, eWID)" is not possible. You'd need an intermediate slot connected to removed():

声明:

Q_SLOTS:
    void somethingRemoved(int, int, int, int);

定义:

void Foobar::somethingRemoved(int sPI, int sWID, int ePI, int eWID) {
    disconnect(sPI, sWID);
    disconnect(ePI, eWID);
}

连接:

connect(x, SIGNAL(removed(int,int,int,int)), foobar, SLOT(somethingRemoved(int,int,int,int)));

这篇关于插槽可以接受的自变量少于信号提供的自变量,怎么办? -Qt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆