The signal and groove mechanism of QT

Source: Internet
Author: User

1, signal and groove mechanism is the core mechanism of QT, to be proficient in QT programming must be aware of signals and slots.
2, signal and slot is an advanced interface, applied to communication between objects, it is the core feature of Qt, is also the important place that QT distinguishes from other toolkit.

3, signal and groove is a self-defined QT communication mechanism, it is independent of the standard C + + language, so to properly handle signals and slots, you must use a QT tool called MOC (Meta Object Compiler), the tool is a C + + preprocessor, It automatically generates the additional code needed for high-level event handling.

4. In many of our familiar GUI toolkits, widgets have a callback function that responds to each action they can trigger, which is usually a pointer to a function.
However, the signals and slots in QT replace these messy function pointers, making it more concise and straightforward to write these communication programs.
Signals and slots can carry any number and any type of parameter, they are completely safe in type and do not produce a core dumps like a callback function.

5. All classes derived from Qobject or its subclasses (for example, qwidget) can contain signals and slots. When an object changes its state, the signal is emitted by the object (emit), which is all that the object has to do, and it does not know who is receiving the signal at the other end.
This is the real message encapsulation, which ensures that the object is used as a real software component. Slots are used to receive signals, but they are normal object member functions. A slot does not know if there is any signal connected to itself. Furthermore, the object is not aware of specific communication mechanisms.

6, a lot of signals can be connected with a single slot, you can also connect a single signal with a lot of slots, or even a signal with another signal is also possible, at this time, regardless of the first signal when the launch system will immediately launch a second signal. In short, signals and slots construct a powerful component programming mechanism.



The signal and groove mechanism of QT

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.