mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-24 02:42:48 +00:00
kdeui: close top-level widgets from the KApplication signal handler
this is much like session management but simply quitting the application does not close the windows, if windows are not closed they will be leaked (KMainWindow and derived classes are created on the heap without parent!) and not saved properly because destructors would not be called Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
38e370d475
commit
4dd219d38b
1 changed files with 24 additions and 4 deletions
|
@ -96,11 +96,31 @@ static const int s_quit_signals[] = {
|
|||
|
||||
static void quit_handler(int sig)
|
||||
{
|
||||
KDE_signal(sig, SIG_DFL);
|
||||
|
||||
if (qApp) {
|
||||
qApp->quit();
|
||||
if (!qApp) {
|
||||
KDE_signal(sig, SIG_DFL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (qApp->type() == KAPPLICATION_GUI_TYPE) {
|
||||
const QWidgetList toplevelwidgets = QApplication::topLevelWidgets();
|
||||
if (!toplevelwidgets.isEmpty()) {
|
||||
kDebug(240) << "closing top-level widgets";
|
||||
foreach (QWidget* topwidget, toplevelwidgets) {
|
||||
if (!topwidget) {
|
||||
continue;
|
||||
}
|
||||
QCloseEvent closeevent;
|
||||
QApplication::sendEvent(topwidget, &closeevent);
|
||||
if (!closeevent.isAccepted()) {
|
||||
kDebug(240) << "not quiting because a top-level widget did not close";
|
||||
return;
|
||||
}
|
||||
}
|
||||
kDebug(240) << "all top-level widgets closed";
|
||||
}
|
||||
}
|
||||
KDE_signal(sig, SIG_DFL);
|
||||
qApp->quit();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Reference in a new issue