插槽可以使用比信号提供的更少的参数,如何?- Qt [英] A slot can take less arguments than provided by the signal, HOW? - Qt

查看:23
本文介绍了插槽可以使用比信号提供的更少的参数,如何?- 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);

(我想要当removed() 发出时,断开连接(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)"是不可能的.你需要一个连接到removed()的中间槽:

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天全站免登陆