A slot can take less arguments than provided by the signal, HOW? - Qt

谁说胖子不能爱 提交于 2019-12-08 11:56:18

问题


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:


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)));


来源:https://stackoverflow.com/questions/21363256/a-slot-can-take-less-arguments-than-provided-by-the-signal-how-qt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!