QComboBox::setView only delete the old view if it is a child

We have ownership for a reason - and there seems to be
no good reason not to accept it here.

[ChangeLog][QtWidgets][QComboBox] QComboBox::setView no longer
deletes the old view directly. It now checks the ownership first.

Change-Id: Icb5e5c0a6e9dc93c1d1c1a90ff57fbcc0786aa60
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>
This commit is contained in:
Thorbjørn Martsum 2015-07-02 07:39:32 +02:00 committed by Thorbjørn Lund Martsum
parent 6a6d793d85
commit b9438e6cbd
2 changed files with 25 additions and 1 deletions

View File

@ -546,7 +546,8 @@ void QComboBoxPrivateContainer::setItemView(QAbstractItemView *itemView)
disconnect(view, SIGNAL(destroyed()),
this, SLOT(viewDestroyed()));
delete view;
if (isAncestorOf(view))
delete view;
view = 0;
}

View File

@ -164,6 +164,7 @@ private slots:
void keyboardSelection();
void setCustomModelAndView();
void updateDelegateOnEditableChange();
void respectChangedOwnershipOfItemView();
};
class MyAbstractItemDelegate : public QAbstractItemDelegate
@ -3169,5 +3170,27 @@ void tst_QComboBox::updateDelegateOnEditableChange()
}
}
void tst_QComboBox::respectChangedOwnershipOfItemView()
{
QComboBox box1;
QComboBox box2;
QTableView *v1 = new QTableView;
box1.setView(v1);
QSignalSpy spy1(v1, SIGNAL(destroyed()));
box2.setView(v1); // Ownership should now be transferred to box2
QTableView *v2 = new QTableView(&box1);
box1.setView(v2); // Here we do not expect v1 to be deleted
QApplication::processEvents();
QCOMPARE(spy1.count(), 0);
QSignalSpy spy2(v2, SIGNAL(destroyed()));
box1.setView(v1);
QCOMPARE(spy2.count(), 1);
}
QTEST_MAIN(tst_QComboBox)
#include "tst_qcombobox.moc"