Qt: How do I handle the event of the user pressing the 'X' (close) button?

前端 未结 4 1096
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-02 06:50

I am developing an application using Qt. I don\'t know which slot corresponds to the event of \"the user clicking the \'X\'(close) button of the window frame\" i.e. this but

4条回答
  •  我在风中等你
    2020-12-02 07:09

    Well, I got it. One way is to override the QWidget::closeEvent(QCloseEvent *event) method in your class definition and add your code into that function. Example:

    class foo : public QMainWindow
    {
        Q_OBJECT
    private:
        void closeEvent(QCloseEvent *bar);
        // ...
    };
    
    
    void foo::closeEvent(QCloseEvent *bar)
    {
        // Do something
        bar->accept();
    }
    

提交回复
热议问题