总结了一下网上的资料,感觉有点奇怪,自己实现的一个版本奉上.
1.main函数里设置参数,最后一个窗口关闭时关闭程序.
app.setQuitOnLastWindowClosed(true);
QT助手上这么写
quitOnLastWindowClosed : bool
This property holds whether the application implicitly quits when the last window is closed.
The default is true.
If this property is true, the applications quits when the last visible primary window (i.e. window with no parent) with the Qt::WA_QuitOnClose attribute set is closed. By default this attribute is set for all widgets except for sub-windows. Refer to Qt::WindowType for a detailed list of Qt::Window objects.
Access functions:
bool quitOnLastWindowClosed ()
void setQuitOnLastWindowClosed ( bool quit )
This property holds whether the application implicitly quits when the last window is closed.
The default is true.
If this property is true, the applications quits when the last visible primary window (i.e. window with no parent) with the Qt::WA_QuitOnClose attribute set is closed. By default this attribute is set for all widgets except for sub-windows. Refer to Qt::WindowType for a detailed list of Qt::Window objects.
Access functions:
bool quitOnLastWindowClosed ()
void setQuitOnLastWindowClosed ( bool quit )
有些人是用的信号/槽实现的
在main函数中将QApplication::lastWindowClosed()信号和QApplication::quit()槽函数相关联
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
void QApplication::lastWindowClosed () [signal] 后面有QT助手的解释,
明显没有我的方法简单方便