Well... Yes, if you implement a function such as the following:
QList<bool> multiconnect
(QObject *sender,
const char *sign,
const QList<QObject
*>
&rcvs,
const QList<const
char*>
&slts
){ if(rcvs.size()!=slts.size())
return QList<bool>();
QList<bool> results;
for(int i=0;i<rcvs.size();i++){
results << connect(sender, sign, rcvs[i], slts[i]);
}
return results;
}
QList<bool> multiconnect(QObject *sender, const char *sign, const QList<QObject*> &rcvs, const QList<const char*> &slts){
if(rcvs.size()!=slts.size())
return QList<bool>();
QList<bool> results;
for(int i=0;i<rcvs.size();i++){
results << connect(sender, sign, rcvs[i], slts[i]);
}
return results;
}
To copy to clipboard, switch view to plain text mode
Then you should be able to call it as:
QList<QObject *> rcvs;
QList<const char *> slts;
rcvs << myObj1 << myObj2 << myObj3;
slts << SLOT(react()) << SLOT(doSomething()) << SLOT(doSomethingElse());
QList<bool> result = multiconnect(this, SIGNAL(clicked()), rcvs, slts);
if(result.isEmpty())
qDebug() << "Bad args count";
else if(result[2]==false)
qDebug() << "SLOT myObj3::doSomethingElse() didn't connect";
QList<QObject *> rcvs;
QList<const char *> slts;
rcvs << myObj1 << myObj2 << myObj3;
slts << SLOT(react()) << SLOT(doSomething()) << SLOT(doSomethingElse());
QList<bool> result = multiconnect(this, SIGNAL(clicked()), rcvs, slts);
if(result.isEmpty())
qDebug() << "Bad args count";
else if(result[2]==false)
qDebug() << "SLOT myObj3::doSomethingElse() didn't connect";
To copy to clipboard, switch view to plain text mode
Of course this can be shortened to a single statement:
multiconnect(this, SIGNAL(clicked()), QList<QObject*>() << myObj1 << myObj2, QList<const char*>() << SLOT("xyz()") << SLOT("abc"));
multiconnect(this, SIGNAL(clicked()), QList<QObject*>() << myObj1 << myObj2, QList<const char*>() << SLOT("xyz()") << SLOT("abc"));
To copy to clipboard, switch view to plain text mode
Bookmarks