Background:
Qt in the user close the window (directly click on the "X" key), the program generally need to do some aftercare things, as far as my current program, both off the USB. How is it implemented?
Body:
First, the ". h" file in the corresponding form contains the header file for #include <QCloseEvent>;.
Second, declare the function void Closeevent (Qcloseevent * event) in the ". h" file; Note: This function has been established within QT to click the "X" button slot, cannot change its function name;
Finally, implement void Closeevent (Qcloseevent * event) in the ". cpp" file for the corresponding form; For example, in its internal implementation to close the USB to reach the form close, the USB descriptor is also destroyed for the purpose.
Reference article:
Functions for closing applications and windows in QT
http://blog.csdn.net/noif1655/article/details/10004777
Rewriting of QT control functions
http://blog.csdn.net/qustdjx/article/details/20130853
Attached: A rough overview of QT signal and slot usage:
In the case of FAKEQQ (LAN-based communication software) I have written,
Establish a signal-to-slot connection in the main function:
QO Bject::connect (&login, SIGNAL (Loginsuccess ()), &panel, SLOT (Openmainpanel () ));
What does each of these parameters mean?
Both login and panel are the two classes that I create by default for the "login form" and "main Panel form".
In the login class, I created a loginsuccess () signal, with an example of a
Signals:
void login_success (void);
This is the signal, no need to implement a specific function, just declare it enough. QT will do the rest of the work.
In the Panel class, I created a slot for Openmainpanel (), with the following use cases:
Public Slots:
void Openmainpanel (void);
The thing to note is that the slot needs to implement a specific function entity, which is exactly what you want to do. For example, in the case of the function name, open the main panel.
How to use it in the program, very simple:
Emit loginsuccess (); Signal to send Login success
Then the program will call the corresponding slot function according to the relationship between the signal and the slot established in main, the example is to open the main panel.
QT Click the "X" button to invoke the Closeevent () function to invoke a specific event