Core of QT ----- Signals & Slots

Source: Internet
Author: User

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 )));

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.