Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.11.1
-
None
-
cd499b72973a4a01d12e2e3ba66e7e16ac1feeb4
Description
The constructor of QLayout sets the parent widget's layout to 'this' (see here). The bug is that this behavior is not documented. For example here:
http://doc.qt.io/qt-5/qlayout.html#QLayout
The "Basic Layouts Example" page does not mention why it creates Layouts without parent widgets, either:
http://doc.qt.io/qt-5/qtwidgets-layouts-basiclayouts-example.html
This can lead to a difficult to debug warning:
QWidget::setLayout: Attempting to set QLayout "" on Widget "", which already has a layout
when the following happens:
- Creating a layout not intended for widget A with it as parent (to avoid a potential memory leak):
QVBoxLayout *mainLayout = new QVBoxLayout(A);
- And giving that widget another layout later:
A->setLayout(anotherLayout);
For an example of this affecting users in the wild, see for example:
https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb/merge_requests/187
Attachments
For Gerrit Dashboard: QTBUG-69761 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
238455,3 | QLayout: Better document QLayout(QWidget *parent) behavior | 5.12 | qt/qtbase | Status: MERGED | +2 | 0 |