summaryrefslogtreecommitdiffstats
path: root/tests/manual/qlayout/vbwidget.cpp
diff options
context:
space:
mode:
authorThomas Fischer <fischer@unix-ag.uni-kl.de>2014-08-24 14:01:26 +0200
committerMarc Mutz <marc.mutz@kdab.com>2014-09-05 00:05:45 +0200
commit983dde1f2f3db76ab26e949d8c2f4f8b968b36be (patch)
treec092b9aa473e4ca41201ab1969f9139ff9db8585 /tests/manual/qlayout/vbwidget.cpp
parent8206a263ab9bca7fef191d299c05294a00ec1c8f (diff)
Avoid adding widget to its own layout
Widgets and layouts added or inserted to a layout are checked for: - Not being NULL - Not being the parent widget of a layout or the layout itself, respectively Without this commit, adding a widget to its own layout would result in a CPU-hogging infinite loop. Now, a warning is written to stderr and the add or insert function call is ignored. The checks are implemented as public functions of QLayoutPrivate and thus accessible in QLayout's descendants to be used in various "addWidget", "insertWidget", etc functions. Unlike 'classical' layouts like QGridLayout, QFormLayout does indeed accept widgets that are NULL. To not break this behavior, any call for the check functions first tests if the widget or layout, respectively, to test is NULL or not and calls the check only in the latter case. Automated tests for QBoxLayout, QGridLayout, and QFormLayout were added. For an unpatched Qt 5.3, each of those automated tests will freeze as explained in QTBUG-40609. For a fixed version, warning messages about invalid parameters to addWidget/addLayout/... calls will be read by QTest::ignoreMessage, resulting in a passed test. Change-Id: I1522d5727e643da3f7c025755975aca9f482676d Task-number: QTBUG-40609 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'tests/manual/qlayout/vbwidget.cpp')
-rw-r--r--tests/manual/qlayout/vbwidget.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/manual/qlayout/vbwidget.cpp b/tests/manual/qlayout/vbwidget.cpp
index 063176625d..ffd918b955 100644
--- a/tests/manual/qlayout/vbwidget.cpp
+++ b/tests/manual/qlayout/vbwidget.cpp
@@ -53,6 +53,7 @@ VbWidget::VbWidget(QWidget *parent) :
QWidget(parent)
{
QVBoxLayout *hb = new QVBoxLayout(this);
+ hb->setObjectName("VbWidget");
QComboBox *combo = new QComboBox(this);
combo->addItem("123");
QComboBox *combo2 = new QComboBox();
@@ -67,4 +68,11 @@ VbWidget::VbWidget(QWidget *parent) :
hb->addWidget(new QDateTimeEdit());
hb->addWidget(new QPushButton("123"));
hb->addWidget(new QSpinBox());
+
+ qDebug("There should be four warnings, but no crash or freeze:");
+ hb->addWidget(this); ///< This command should print a warning, but should not add "this"
+ hb->addWidget(Q_NULLPTR); ///< This command should print a warning, but should not add "NULL"
+ hb->addLayout(hb); ///< This command should print a warning, but should not add "hb"
+ hb->addLayout(Q_NULLPTR); ///< This command should print a warning, but should not add "NULL"
+ qDebug("Neither crashed nor frozen");
}