From fcb6a74d2370b8b56c2e7637c062e61050829d09 Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Mon, 4 Jun 2018 15:55:07 +0200 Subject: [PATCH] Fix crash when removing layer with attribute table open Fix #19054 --- src/gui/attributetable/qgsfeaturelistview.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/gui/attributetable/qgsfeaturelistview.cpp b/src/gui/attributetable/qgsfeaturelistview.cpp index 40b9491b590..93f9c37f22e 100644 --- a/src/gui/attributetable/qgsfeaturelistview.cpp +++ b/src/gui/attributetable/qgsfeaturelistview.cpp @@ -400,6 +400,11 @@ void QgsFeatureListView::ensureEditSelection( bool inSelection ) { QTimer::singleShot( 0, this, [ this, inSelection, validEditSelectionAvailable ]() { + // The layer might have been removed between timer start and timer triggered + // in this case there is nothing left for us to do. + if ( !layerCache() ) + return; + int rowToSelect = -1; if ( inSelection ) @@ -423,7 +428,9 @@ void QgsFeatureListView::ensureEditSelection( bool inSelection ) rowToSelect = 0; if ( rowToSelect != -1 ) + { setEditSelection( mModel->mapToMaster( mModel->index( rowToSelect, 0 ) ), QItemSelectionModel::ClearAndSelect ); + } } ); } }