PDA

View Full Version : Can i call a Signal normally?



mahesh113
29th May 2012, 17:12
Like slots can be called normally, Can I call a Signal normally?

Lykurg
29th May 2012, 22:21
For what? What do you expect by calling a signal normally? A signal typically has no definition.

ChrisW67
29th May 2012, 23:07
Moc generates an implementation that is just a wrapper around QMetaObject::activate() and the "emit" or "Q_EMIT" pseudo-keyword is #defined away (see src/corelib/kernel/qobjectdefs.h). So, in short, you are always calling the signal directly.

The original question could have been answered in about 5 minutes by writing a quick test program to try it.

The only reason I could imagine you would care is if you wanted to use the signal as a traditional callback function, using std::tr1::function and ::bind for example. The "emit" keyword doesn't fit there.

sonulohani
1st June 2012, 12:17
You can call signal or slot like this---->


One signal can be connected to many slots:


connect(slider, SIGNAL(valueChanged(int)),
spinBox, SLOT(setValue(int)));
connect(slider, SIGNAL(valueChanged(int)),
this, SLOT(updateStatusBarIndicator(int)));


Many signals can be connected to the same slot:

connect(lcd, SIGNAL(overflow()),
this, SLOT(handleMathError()));
connect(calculator, SIGNAL(divisionByZero()),
this, SLOT(handleMathError()));

A signal can be connected to another signal:

connect(lineEdit, SIGNAL(textChanged(const QString &)),
this, SIGNAL(updateRecord(const QString &)));


When the first signal is emitted, the second signal is emitted as well.
Apart from that, signal–signal connections are indistinguishable from
signal–slot connections.