A slot can take less arguments than provided by th

2019-06-13 05:29发布

I have a signal which its declaration is:

void removed(int sPI, int sWID , int ePI, int 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);

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

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

1条回答
在下西门庆
2楼-- · 2019-06-13 06:01

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.

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

Declaration:

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

Definition:

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

Connect:

connect(x, SIGNAL(removed(int,int,int,int)), foobar, SLOT(somethingRemoved(int,int,int,int)));
查看更多
登录 后发表回答