diff options
author | Raschbauer, Reinhard <reinhard.raschbauer@bbv.ch> | 2017-05-17 11:03:02 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2017-08-04 08:36:29 +0000 |
commit | 52c66e85156eb0547777ada07fe67e5e5ef653da (patch) | |
tree | a18415541a9687ad884c6a55a3e19265bab59ffd /tests | |
parent | 5169d588a599036aa1962f518a7c321f5e3e7296 (diff) |
QAbstractItemView: fix nullptr violation
If in a slot connected to QAbstractItemView::clicked
QAbstractItemView::setModel(nullptr) is called the method
QAbstractItemView::mouseReleaseEvent will cause a segmentation fault.
The problem is that the method QAbstractItemView::model used in
QAbstractItemView::mouseReleaseEvent will return a nullptr if a null
model was set. The solution is to used d->model since it is always a
valid model. (See line d->model =
(model ? model : QAbstractItemModelPrivate::staticEmptyModel());
in method QAbstractItemView::setModel)
Change-Id: I6f01bdeac64495ee4a76adcc7bf8da8a7719ef4d
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp index f2cf78e8ac..83912fa2c3 100644 --- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp +++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp @@ -153,6 +153,7 @@ private slots: void testClickToSelect(); void testDialogAsEditor(); void QTBUG46785_mouseout_hover_state(); + void testClearModelInClickedSignal(); }; class MyAbstractItemDelegate : public QAbstractItemDelegate @@ -2266,5 +2267,29 @@ void tst_QAbstractItemView::QTBUG46785_mouseout_hover_state() QTRY_VERIFY(delegate.m_paintedWithoutHover); } +void tst_QAbstractItemView::testClearModelInClickedSignal() +{ + QStringList list{"A", "B"}; + QStringListModel model(list); + + QListView view; + view.setModel(&model); + view.show(); + + QWidget::connect(&view, &QListView::clicked, [&view](const QModelIndex &index) + { + view.setModel(nullptr); + QCOMPARE(index.data().toString(), QStringLiteral("B")); + }); + + QModelIndex index = view.model()->index(1, 0); + QVERIFY(index.isValid()); + QPoint p = view.visualRect(index).center(); + + QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, p); + + QCOMPARE(view.model(), nullptr); +} + QTEST_MAIN(tst_QAbstractItemView) #include "tst_qabstractitemview.moc" |