I am studying Drone Programming in C . I found this function :
void Vehicle::_announceArmedChanged(bool armed)
But when I search for it, all the code calls this function without a parameter, such as:
connect(this, &Vehicle::armedChanged, this, &Vehicle::_announceArmedChanged);
In this case, where does the program get the armed
status?
CodePudding user response:
In this situation, announceArmedChanged()
is a callback function. The code you showed is not calling announceArmedChanged()
. It is passing the memory address of announceArmedChanged
to QObject::connect()
of the Qt framework, which will remember the address and associate it with the specified armedChanged
event. When other code later triggers the armedChanged
event with an appropriate status value, announceArmedChanged()
will then be called with that value.
Read Signals & Slots in Qt's documentation for more details.
CodePudding user response:
Pointers to member functions
A pointer to non-static member function
f
which is a member of classC
can be initialized with the expression&C::f
exactly. Expressions such as&(C::f)
or&f
insideC
's member function do not form pointers to member functions.