QT Click the "X" button to invoke the Closeevent () function to invoke a specific event

Source: Internet
Author: User

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

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.