From 6a829e0d09bd81607d192040a1b6c3c12a58aad7 Mon Sep 17 00:00:00 2001 From: David Faure Date: Sat, 12 Mar 2022 01:48:07 +0100 Subject: QCompleter: fix crash when setting the same model twice Found when retesting the testcase completer.zip from QTBUG-54642 Change-Id: Id84eefeb3a33dc6d790cfa23755352381cc097a9 Reviewed-by: Volker Hilsheimer (cherry picked from commit 7382e5735ea734fe5e5777518394963593603c32) Reviewed-by: Qt Cherry-pick Bot --- tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests') diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp index 4146a6632d..358f5fe1e7 100644 --- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp @@ -1653,6 +1653,16 @@ void tst_QComboBox::setModel() QCOMPARE(box.rootModelIndex(), rootModelIndex); box.setModel(box.model()); QCOMPARE(box.rootModelIndex(), rootModelIndex); + + // check that setting the same model as the completer's doesn't crash + QCompleter *completer = new QCompleter(&box); + box.setEditable(true); + box.setCompleter(completer); + auto *listModel = new QStringListModel({ "one", "two" }, completer); + completer->setModel(listModel); + QCOMPARE(listModel->rowCount(), 2); // make sure it wasn't deleted + box.setModel(listModel); + QCOMPARE(listModel->rowCount(), 2); // make sure it wasn't deleted } void tst_QComboBox::setCustomModelAndView() -- cgit v1.2.3