Fix bug with QLayout::replaceWidget(a, a)

It should effectively leave the layout untouched

Fixes: QTBUG-69706
Change-Id: I4d8232895bf1d1ae0d1b73156ef6ec6001d8968a
Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
This commit is contained in:
Jan Arve Saether 2019-05-03 15:47:57 +02:00 committed by Jan Arve Sæther
parent 7dd71e8125
commit 2b7edd0534
2 changed files with 6 additions and 0 deletions

View File

@ -1156,6 +1156,8 @@ QLayoutItem *QLayout::replaceWidget(QWidget *from, QWidget *to, Qt::FindChildOpt
Q_D(QLayout);
if (!from || !to)
return 0;
if (from == to) // Do not return a QLayoutItem for \a from, since ownership still
return nullptr; // belongs to the layout (since nothing was changed)
int index = -1;
QLayoutItem *item = 0;

View File

@ -571,6 +571,10 @@ void tst_QBoxLayout::replaceWidget()
QCOMPARE(boxLayout->indexOf(replaceFrom), 1);
QCOMPARE(boxLayout->indexOf(replaceTo), -1);
QCOMPARE(boxLayout->count(), 3);
boxLayout->replaceWidget(replaceFrom, replaceFrom);
QCOMPARE(boxLayout->count(), 3);
delete boxLayout->replaceWidget(replaceFrom, replaceTo);
QCOMPARE(boxLayout->indexOf(replaceFrom), -1);