QT is a cross-platform C++ GUI application framework. It provides a rich set of widgets, is object-oriented, easy to expand, and has the characteristics of true component programming. What is more eye-catching is that currently Linux The most popular KDE desktop environment in the world is built on the basis of the QT library. QT supports the following platforms: MS/WINDOWS-95, 98, NT and 2000; UNIX/X11-Linux, Sun Solaris, HP-UX, Digital Unix, IBM AIX, SGI IRIX; EMBEDDED - Linux platform with framebuffer support. With the rapid development and popularity of KDE, QT is likely to become the first choice for GUI when developing software on the Linux window platform.
Overview
The signal and slot mechanism is the core mechanism of QT. To be proficient in QT programming, you must have an understanding of signals and slots. Signals and slots are a high-level interface that is used for communication between objects. It is the core feature of QT and an important place that distinguishes QT from other toolkits. Signals and slots are a communication mechanism defined by QT. It is independent of the standard C/C++ language. Therefore, to correctly handle signals and slots, you must use a QT tool called moc (Meta Object Compiler), which is A C++ preprocessor that automatically generates the additional code required for high-level event handling.
In many GUI toolkits we are familiar with, widgets have a callback function to respond to each action they can trigger. This callback function is usually a pointer to a certain function. pointer. However, in QT, signals and slots replace these messy function pointers, making it simpler and clearer for us to write these communication programs. Signals and slots can carry any number of parameters of any type. They are completely type-safe and will not produce core dumps like callback functions.
All classes derived from QObject or its subclasses (such as Qwidget) can contain signals and slots. When an object changes its state, the signal is emitted by the object. This is all the object has to do. It does not know who is receiving the signal on the other end. This is true information encapsulation, which ensures that the object is used as a real software component. Slots are used to receive signals, but they are ordinary object member functions. A slot does not know whether any signals are connected to it. Furthermore, the subject does not understand the specific communication mechanism.
You can connect many signals to a single slot, or you can connect a single signal to many slots. It is even possible to connect one signal to another signal. Whenever the first signal is transmitted the system will immediately transmit the second signal. In short, signals and slots constitute a powerful component programming mechanism.
Signals and slots are type-safe (signatures match), that is, the number of parameter types of the signal and the slot must be the same, or the number of parameters of the slot can be less than the number of parameters of the signal, but there is a lack of The parameter must be the last parameter or parameters of the signal parameters.