summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThorbjørn Martsum <tmartsum@gmail.com>2015-07-02 07:39:32 +0200
committerThorbjørn Lund Martsum <tmartsum@gmail.com>2015-07-08 17:37:33 +0000
commitb9438e6cbdc9768253c7c696e4d9f085c067fe31 (patch)
treeea32bfe665315f17bc9e5a7e75425663f76df4e6
parent6a6d793d857e580cf63b689d03f891710f46487a (diff)
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>
-rw-r--r--src/widgets/widgets/qcombobox.cpp3
-rw-r--r--tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp23
2 files changed, 25 insertions, 1 deletions
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp
index 0ecbb8a435..232ba6698e 100644
--- a/src/widgets/widgets/qcombobox.cpp
+++ b/src/widgets/widgets/qcombobox.cpp
@@ -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;
}
diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
index c409698ec0..3835981725 100644
--- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
+++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
@@ -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"