From fde358dd9069d0695f113ec6ba98efebedd1e520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Sun, 3 Mar 2024 22:06:06 +0100 Subject: Delete QComboBoxPrivateContainer while the combo box is still alive Destroying the QComboxBox will, once it reaches the QWidget destructor, close all popups, including the QComboBoxPrivateContainer, which emits signals on behalf of the QComboBox, that is now gone. Regression after d8e110054876b1cbf186e95bac5561a237ee1c13. The old-syle signal-slot syntax had the advantage of not delivering signals to slots in derived classes after that derived class's destructor had finished running (because we called via the virtual qt_metacall). The new syntax made no checks, so a conversion from the old to the new syntax may introduce crashes or other data corruptions at runtime if the destructor had completed. See 0e72a846d379ba02ff80ecac2526640a05b872b6. We also need a QPointer for the QComboBoxPrivateContainer, as the container may be deleted from outside QComboBox, as seen in the tst_QGraphicsProxyWidget::bypassGraphicsProxyWidget() test, where the QGraphicsProxyWidget proxies the QComboBoxPrivateContainer. Pick-to: 6.7 6.6 6.5 Change-Id: I7590cc2821c73a6762f281504aa62f0c2b472252 Reviewed-by: Axel Spoerl --- src/widgets/widgets/qcombobox.cpp | 3 +++ src/widgets/widgets/qcombobox_p.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 76904aaadd..06de5566ff 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -1455,6 +1455,9 @@ QComboBox::~QComboBox() } QT_CATCH(...) { ; // objects can't throw in destructor } + + // Dispose of container before QComboBox goes away + delete d->container; } /*! diff --git a/src/widgets/widgets/qcombobox_p.h b/src/widgets/widgets/qcombobox_p.h index 6ea0065d8c..723d637ae2 100644 --- a/src/widgets/widgets/qcombobox_p.h +++ b/src/widgets/widgets/qcombobox_p.h @@ -380,7 +380,7 @@ public: std::array modelConnections; QAbstractItemModel *model = nullptr; QLineEdit *lineEdit = nullptr; - QComboBoxPrivateContainer *container = nullptr; + QPointer container; #ifdef Q_OS_MAC QPlatformMenu *m_platformMenu = nullptr; #endif -- cgit v1.2.3