can a single statement work in signal/slot mechanism
hi..
i was just guessing that if there is any mechanism available in qt through which single signal can emit different slots just with a single statement..:rolleyes:
Code:
connect(navigate,SIGNAL(recordClicked()),navigate,SLOT(disableRecordButton()));
connect(navigate,SIGNAL(recordClicked()),progress,SLOT(startProgress()));
can this work be done by single statement
Re: can a single statement work in signal/slot mechanism
Well... Yes, if you implement a function such as the following:
Code:
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;
}
Then you should be able to call it as:
Code:
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";
Of course this can be shortened to a single statement:
Code:
multiconnect(this, SIGNAL(clicked()), QList<QObject*>() << myObj1 << myObj2, QList<const char*>() << SLOT("xyz()") << SLOT("abc"));