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 <axel.spoerl@qt.io>
This commit is contained in:
Tor Arne Vestbø 2024-03-03 22:06:06 +01:00
parent 0fa0d01c36
commit fde358dd90
2 changed files with 4 additions and 1 deletions

View File

@ -1455,6 +1455,9 @@ QComboBox::~QComboBox()
} QT_CATCH(...) {
; // objects can't throw in destructor
}
// Dispose of container before QComboBox goes away
delete d->container;
}
/*!

View File

@ -380,7 +380,7 @@ public:
std::array<QMetaObject::Connection, 8> modelConnections;
QAbstractItemModel *model = nullptr;
QLineEdit *lineEdit = nullptr;
QComboBoxPrivateContainer *container = nullptr;
QPointer<QComboBoxPrivateContainer> container;
#ifdef Q_OS_MAC
QPlatformMenu *m_platformMenu = nullptr;
#endif