From 5e64957ee4162ecf4456306a530a68761c2b127f Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Tue, 25 Sep 2018 18:35:31 +0200 Subject: Fix QCompleter popups preventing the application from exiting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Due to an implementation detail regarding setParent() and setWindowFlags(), if a QCompleter popup ends up being the last open window after closing the main window, the application would be prevented from exiting even after selecting an item in the popup. This is due to adjustQuitOnCloseAttribute() not being called when passing a Qt::Popup flag to setParent(parent, windowFlags). Use setWindowFlags() directly, which adjusts the quit on close attribute, and allows an application to exit properly. Change-Id: Ic4cff9504df268556d851e40d5ae08b7ed4dc3bf Fixes: QTBUG-69924 Reviewed-by: Tor Arne Vestbø --- src/widgets/util/qcompleter.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/widgets/util/qcompleter.cpp b/src/widgets/util/qcompleter.cpp index 599b983748..22fb0a511d 100644 --- a/src/widgets/util/qcompleter.cpp +++ b/src/widgets/util/qcompleter.cpp @@ -1233,7 +1233,14 @@ void QCompleter::setPopup(QAbstractItemView *popup) Qt::FocusPolicy origPolicy = Qt::NoFocus; if (d->widget) origPolicy = d->widget->focusPolicy(); - popup->setParent(0, Qt::Popup); + + // Mark the widget window as a popup, so that if the last non-popup window is closed by the + // user, the application should not be prevented from exiting. It needs to be set explicitly via + // setWindowFlag(), because passing the flag via setParent(parent, windowFlags) does not call + // QWidgetPrivate::adjustQuitOnCloseAttribute(), and causes an application not to exit if the + // popup ends up being the last window. + popup->setParent(nullptr); + popup->setWindowFlag(Qt::Popup); popup->setFocusPolicy(Qt::NoFocus); if (d->widget) d->widget->setFocusPolicy(origPolicy); -- cgit v1.2.3