PDA

View Full Version : How Hand the close button in MainWindow



phuong_90
24th October 2011, 18:58
Hello, I have a problem. I have a MainWindow, and I want hand event when user click close button on MainWindow (x-button). What I should do?

amleto
24th October 2011, 19:14
in your mainwindow, implement closevent(...).


http://doc.qt.nokia.com/latest/qwidget.html#closeEvent

If you haven't already, you will need to subclass QMainWindow so that you can implement the method.

phuong_90
25th October 2011, 02:05
I try implement function closeEvent, but my Window still close! Help me!

void MainWindow::closeEvent(QCloseEvent *event)
{
event->ignore();
qDebug()<<"Can't close Window";
}

Spitfire
25th October 2011, 09:45
Have you defined the method correctly in your header file?

protected:
void closeEvent( QCloseEvent* event );

amleto
25th October 2011, 10:25
And Importantly, does it inherit from QWidget etc etc.

Please pay attention to my sig. cut and paste a complete example, otherwise you are making everybody guess!