What if you emit a FUNCTION (not signals) ....
-
Seems it will NOT cause any problem though it is bad writing.
For each signals which defined at class body, moc will generate the following:
void myClass::signalA()
{
QMetaObject::activate(this, &staticMetaObject, 0, 0);
}But for function, moc will not do the same thing above. So when you emit a function by careless. The keyword “emit” just ignored.
What do you think?
-
Emit is not really needed, it defined as nothing
@
#define emit
@
So emit is not a keyword, it's a define :-)You can leave emit out if you want, it's just for better code readability. So if someone sees this:
@
void MyClass::foo()
{
... // doing some calculation
ChangedValue(abc);
...
}
@he does not know, whether ChangedValue is calling someone else, is a sub functions (that's how it looks like) etc.
Or he sees this
@
void MyClass::foo()
{
... // doing some calculation
emit ChangedValue(abc);
...
}
@which makes it clear: a signal is send to some connected objects.
-
Hi, Andre
Gerolf makes it clearer:
1) it is OK to emit the function 2) it is also OK to call signals directly without "emit"
Though both 1) and 2) looks strange.
About Andre's question" why? Why would you want to emit a function? What would that mean?"
I once wrote some codes of "emit" the function by my careless, and assume that something serious will happen. Actually , nothing happened.
-
Indeed, Gerolfs's explanation that emit is defined to nothing is quite clear. I simply did not understand your question well enough at the first read.
Yes, you can "emit" a function (though no slot will be called, at least not by Qt's doing) and you can simply call a signal, but as Gerolf showed that results in unclear code. That you can, does not mean that you should.
Technically, it is all the same, but conceptually it is completely different, in my book. Not emitting signals or emitting functions in my opinion is bad coding practice. You mislead other developers (and yourself), which is not a good thing.
-