I assumed from experience with Qt that all signals and slots required identical signatures. Recently I seen Qt code that connects totally different signatures, and the slot are called when the signal they were connected to is emitted. For example, a signal that emits a couple objects to a slot that takes no arguments.
I know about the different ways QObject::connect() can be called for connecting signals and slots, still I figured the rule was that their signatures are required to be the same.
CodePudding user response:
From the documentation on Qt Signals and Slots:
The signature of a signal must match the signature of the receiving slot. (In fact a slot may have a shorter signature than the signal it receives because it can ignore extra arguments.)
Essentially, you can drop arguments from the end of your slot's signature (you can not drop them from the beginning or middle).
If you need to ignore arbitrary arguments, you can make your slot's signature identical to the signal and then use the Q_UNUSED
macro for any arguments you want to ignore. For example:
void MyClass::mySlot(int foo, double argIDontCareAbout, int bar)
{
Q_UNUSED(argIDontCareAbout)
}
The point of the Q_UNUSED
macro is to simply to suppress compiler warnings about unused arguments.