I don't think this is possible directly using what Qt Object system gives you. The main reason is that the connection concept is almost completly driven fron the signal end, and there is no way (using APIs) to find out number of singals trigerring a objects slot. Other way round is possible, you could find out how many slots are connected to a given signal.
This is what I would do.
Educate the slot (or the object of the slot) about the signal sender() object, so that the slot will only care the incovation if the sender() has matched.
i.e. whenever a dynamic connection is made to a slot(), immediatly the sender is also set, code will look somthing like
connect(pushButton1, SIGNAL(clicked()), object, SLOT(singularSlot()));
object->setSignalSender(pushButton1);
connect(pushButton1, SIGNAL(clicked()), object, SLOT(singularSlot()));
object->setSignalSender(pushButton2); // this will overwrite the pushButton1
{
...
public:
{
onlySender = sender;
}
public slots:
singularSlot()
{
if(onlySender == sender())
{
// setValue();
}
}
connect(pushButton1, SIGNAL(clicked()), object, SLOT(singularSlot()));
object->setSignalSender(pushButton1);
connect(pushButton1, SIGNAL(clicked()), object, SLOT(singularSlot()));
object->setSignalSender(pushButton2); // this will overwrite the pushButton1
class Object : public QObject
{
...
public:
setSignalSender(QObject * sender)
{
onlySender = sender;
}
public slots:
singularSlot()
{
if(onlySender == sender())
{
// setValue();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks