There is no big difference between a slot function and a normal C + + member function. They can also be virtual, can be overridden, can be public, protected, or private, can be called by other C + + functions, and arguments can be of any type. If you want to say the difference, that is, the slot function can be connected to a signal, when this signal occurs, it can be automatically invoked.
The Connect () statement has a prototype similar to the following:
Connect (sender, SIGNAL (SIGNAL), receiver, SLOT (SLOT));
Here, sender and receiver are qobject types, Singal and slot are function signatures that have no parameter names. Singal () and slot () macros are used to convert arguments to strings.
In depth, there are more possible uses for the signal slots, as shown below.
A signal can be connected with multiple slots:
Connect (slider, SIGNAL (valuechanged (int)),
Spinbox, SLOT (setValue (int)));
Connect (slider, SIGNAL (valuechanged (int)),
This, SLOT (updatestatusbarindicator (int)));
Note that if this is the case, these slots will be called one after another, but the order of their invocation is indeterminate.
Multiple signals can be connected to a slot:
Connect (LCD, SIGNAL (overflow ()),
This, SLOT (Handlematherror ()));
Connect (Calculator, SIGNAL (Divisionbyzero ()),
This, SLOT (Handlematherror ()));
This means that whenever any one of the signals is emitted, the slot is invoked.
A signal can be connected to another signal:
Connect (Lineedit, SIGNAL (textchanged (const QString &)),
This, SIGNAL (UpdateRecord (const QString &)));
This is to say that when the first signal is emitted, the second signal is emitted. In addition, this signal-signal form and signal-groove form is no different.
Slots can be unlinked:
Disconnect (LCD, SIGNAL (overflow ()),
This, SLOT (Handlematherror ()));
This is not often the case, because QT automatically cancels all the slots connected to the object after the object deletes it.
For the proper connection of the signal slot, the number, type, and order of parameters of the signal and slot must be the same, for example:
Connect (FTP, SIGNAL (rawcommandreply (int, const QString &)),
This, SLOT (processreply (int, const QString &)));
An exception to this is that if the signal has more parameters than the slot, then those parameters after this parameter are ignored, for example:
Connect (FTP, SIGNAL (rawcommandreply (int, const QString &)),
This, SLOT (checkerrorcode (int)));
Here, the const QString & This parameter is ignored by the slot.