QT GUI MainWindow窗口关闭事件

2014-11-23 23:36:34 · 作者: · 浏览: 7

有一些堵塞程序,在关闭gui时,可能仍在运行。

所以要在关闭窗口时,同时关闭它们。

这就需要拦截关闭窗口的信号。

这里重载关闭事件,和按键事件。

void closeEvent(QCloseEvent *e);

void keyPressEvent(QKeyEvent *e);

#include

#include

void MainWindow::closeEvent(QCloseEvent *e)

{

//close

}

void MainWindow::keyPressEvent(QKeyEvent *e)

{

if(e->key()==Qt::Key_Escape){

//close

}

}

LaoKa