问题
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