I'm a beginner in Qt and trying to understand the SIGNAL
and SLOT
macros. When I'm learning to use the connect
method to bind the signal and slot, I found the tutorials on Qt's official reference page uses:
connect(obj1, SIGNAL(signal(int)), obj2, SLOT(slot()))
However, this also works very well:
connect(obj1, &Obj1::signal, obj2, &Obj2::slot)
So what exactly do the macros SIGNAL
and SLOT
do? Do they just look for the signal in the class the object belongs to and return the address of it?
Then why do most programmers use these macros instead of using &Obj1::signal
since the latter appears to be simpler and you don't need to change the code if the parameters of the signal function change?