Details
-
Bug
-
Resolution: Done
-
P4: Low
-
None
-
4.8.5, 5.3.1
-
None
-
Gentoo Linux, mostly stable, with additional kde and qt repositories through layman
-
983dde1f2f3db76ab26e949d8c2f4f8b968b36be
Description
Consider the following example (valid both for Qt4 and Qt5):
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
Widget "centralWidget" is added to layout "boxLayout" which is layouting just this widget. Obviously, this "addWidget" call does not make sense, but it may happen due to copy&paste errors or auto-complete madness in editors/IDEs.
When compiling and running such a program as shown above, both with Qt 4.8.5 and 5.3.1, the program hogs the CPU and freezes from the user's perspective.
Qt should not accept adding a widget to its own layout. Such a statement should be ignored and/or a warning should be printed to stderr, but silently accepting it and then just freezing is not an option.
A brief look into Qt's source code lets me suggest to enhance static bool checkWidget(..) in qboxlayout.cpp for a "self-insertion" test.
Maybe a more global solution is necessary, as QFormLayout is affected by a similar issue. A modified example using the following code snipplet shows the same behaviour:
QFormLayout *formLayout = new QFormLayout(centralWidget);
formLayout->addRow(centralWidget);
In case you are going to fix this issue, don't forget to add a test to tst_qboxlayout.cpp and friends
Attachments
For Gerrit Dashboard: QTBUG-40609 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
93071,10 | Avoid adding widget to its own layout | 5.3 | qt/qtbase | Status: MERGED | +2 | 0 |
93162,1 | Adding automated tests for QTBUG-40609 | 5.3 | qt/qtbase | Status: ABANDONED | -2 | 0 |
94172,1 | Avoid adding invalid widgets to a QStackedLayout | 5.3 | qt/qtbase | Status: ABANDONED | 0 | 0 |