emit
is just syntactic sugar. If you look at the pre-processed output of function that emits a signal, you'll see emit
is just gone.
The "magic" happens in the generated code for the signal emitting function, which you can look at by inspecting the C++ code generated by moc.
For example a foo
signal with no parameters generates this member function:
void W::foo()
{
QMetaObject::activate(this, &staticMetaObject, 0, 0);
}
And the code emit foo();
is pre-processed to simply foo();
emit
is defined in Qt/qobjectdefs.h
(in the open-source flavor of the source anyway), like this:
#ifndef QT_NO_EMIT
# define emit
#endif
(The define guard is to allow you to use Qt with other frameworks that have colliding names via the no_keywords
QMake config option.)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…