The signals and slots mechanisms are fundamental to QT.
The slots and C ++ member functions are almost the same. They can be defined as virtual, overloaded, public, protected, or private. Can be the same as other member functions in C ++.
Directly called. A parameter can be defined as any type. Unlike other member functions, it can connect to signal. It can be called automatically when signal is released (emitted.
They are in the following format:
Connect (sender, signal (signal), explorer, slot (slot ));
Sender and consumer er must be pointers to a qobject object. While signal and slot only need to specify the parameter type and do not write the output name.
The following are some possible examples.
A: One signal can connect multiple slots.
For example, connect (slider, signal (valuechange (INT), spinbox, slot (setvalue (INT )));
Connect (slider, signal (valuechange (INT), this, slot (updatevalue (INT )));
B: multiple signal can connect to one slots.
Connect (LCD, signal (overflow ()),
This, slot (handlematherror ()));
Connect (calculator, signal (divisionbyzero ()),
This, slot (handlematherror ()));
C: One signal can connect to other signal.
Connect (lineedit, signal (textchanged (const qstring &)),
This, signal (UpdateRecord (const qstring &)));
D: The connection can be deleted.
Disconnect (LCD, signal (overflow ()),
This, slot (handlematherror ()));
To successfully connect signal to slot, the parameter type and quantity must be the same.
Connect (FTP, signal (rawcommandreply (INT, const qstring &)),
This, slot (processreply (INT, const qstring &)));
However, nothing is absolute. If the signal parameter is more than the slot parameter, the extra parameter can be ignored.
For example: connect (FTP, signal (rawcommandreply (INT, const qstring &)),
This, slot (checkerrorcode (INT )));