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:
Ivailo Monev 2022-12-23 17:11:10 +02:00
parent 38e370d475
commit 4dd219d38b

View file

@ -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();
}
/*