Priority: P4: Low
Affects Version/s: 4.8.5, 5.3.1
Fix Version/s: None
Component/s: Widgets: Layout
Environment:Gentoo Linux, mostly stable, with additional kde and qt repositories through layman
Consider the following example (valid both for Qt4 and Qt5):
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);
In case you are going to fix this issue, don't forget to add a test to tst_qboxlayout.cpp and friends