有一些堵塞程序,在关闭gui时,可能仍在运行。
所以要在关闭窗口时,同时关闭它们。
这就需要拦截关闭窗口的信号。
这里重载关闭事件,和按键事件。
void closeEvent(QCloseEvent *e);
void keyPressEvent(QKeyEvent *e);
void keyPressEvent(QKeyEvent *e);
#include <QKeyEvent>
#include <QEvent>
#include <QEvent>
void MainWindow::closeEvent(QCloseEvent *e)
{
{
//close
}
void MainWindow::keyPressEvent(QKeyEvent *e)
{
if(e->key()==Qt::Key_Escape){
//close
}
void MainWindow::keyPressEvent(QKeyEvent *e)
{
if(e->key()==Qt::Key_Escape){
//close
}
}
}
转载于:https://blog.51cto.com/no001/282807