SIGNAL and SLOT: are them 1 or 2?
-
Hello. http://qt-project.org/doc/qt-5.0/qtcore/qmetamethod.html#MethodType-enum states that QMetaMethod::Signal is defined to 1, while QMetaMethod::Slot is 2. The same time, if we look into qobjectdefs.h, it says:
@# define SLOT(a) qFlagLocation("1"#a QLOCATION)define SIGNAL(a) qFlagLocation("2"#a QLOCATION)@
That is, macro SLOT () adds 1 to method's signature, whereas macro SIGNAL () adds 2.
Is this intended, or did it happened randomly, or just for fun to further complicate matters, or what? -
[quote author="mcosta" date="1363872399"]Hi,
this macro defines Method Location that is
@
private --> 0
protected --1
public --> 2
@then your code define SLOT as protected and SIGNAL as PUBLIC[/quote]
What exactly macro do you mean? I've quoted definitions of SLOT and SIGNAL from the header, no notion of private or protected there (which, by the way, would require calling some QObject or QMetaObject methods). If I write
@ qDebug() << SLOT(abcde);
qDebug() << SIGNAL(defgh);@I get exactly
@1abcde
2defgh
@in the output. These macros do nothing but substitute '1' or '2' at the head of the string, and add FILE:LINE (something like "main.cpp:15") past the ending zero char, nothing more.
-
Hi,
These macros are used by moc to make the Qt magic work. You can dig in the moc generated files and moc's sources to find out more about how they work.
-
moc reads the supplied header files and generates implementation code containing lookup tables for signals and slots using names prefixed with 0, 1 or 2 for internal purposes.
The macros do the matching manipulation for the C++ compiler and programmer's benefit so that the connect() function ultimately uses similarly mangled names.
-
Hell yeah, that's pretty obvious, why are you writing it anyway? My question was: how come QMetaMethod::Signal equals to 1, while the SIGNAL () macro prefixes names with "2", and in reverse for slots.
Wouldn't it be more convenient, if the two digits were the same?
Even more, if SIGNAl () and SLOT () were explicitely standardized? Currently if you have the only the signature of a signal in a string, you have to use something like "QObject::connect(sender, sender->metaObject ()->method(sender->metaObject ()->indexOfMethod(signal))..." thus using QMetaMethod-aware overload of QObject::connect. Maybe, just adding "2" to it would be more convenient, as of programmer's side, but currently it's illegal, because the definition of SIGNAL is obscured.
Same for slots.
(Of course, these talks were of any sence earlier. Qt5.0 supports connecting signals to arbitrary functors, so we're just moving to pure lambdas. All aboard!
Yet even lambdas have to be built from strings.)