Skip to content

Commit 8609a2f

Browse files
committedJun 21, 2018
Do not crash on exit due to dangling layer pointer (fixes #18732)
When using attribute dialog to edit attributes of multiple selected features, the dialog may stay alive until QGIS exits (parented to QgisApp) and its internal QgsActionMenu would try to reload actions when they get removed in ~QgisApp, referring to a deleted map layer, so let's clean things up when the layer gets deleted to avoid trouble later.
1 parent 692f439 commit 8609a2f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed
 

‎src/gui/qgsactionmenu.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ void QgsActionMenu::init()
4747
connect( mLayer, &QgsVectorLayer::editingStarted, this, &QgsActionMenu::reloadActions );
4848
connect( mLayer, &QgsVectorLayer::editingStopped, this, &QgsActionMenu::reloadActions );
4949
connect( mLayer, &QgsVectorLayer::readOnlyChanged, this, &QgsActionMenu::reloadActions );
50+
connect( mLayer, &QgsMapLayer::willBeDeleted, this, &QgsActionMenu::layerWillBeDeleted );
5051

5152
reloadActions();
5253
}
@@ -167,6 +168,15 @@ void QgsActionMenu::reloadActions()
167168
emit reinit();
168169
}
169170

171+
void QgsActionMenu::layerWillBeDeleted()
172+
{
173+
// here we are just making sure that we are not going to have reloadActions() called again
174+
// with a dangling pointer to a layer when actions get removed on QGIS exit
175+
clear();
176+
mLayer = nullptr;
177+
disconnect( QgsGui::mapLayerActionRegistry(), &QgsMapLayerActionRegistry::changed, this, &QgsActionMenu::reloadActions );
178+
}
179+
170180

171181
QgsActionMenu::ActionData::ActionData( QgsMapLayerAction *action, QgsFeatureId featureId, QgsMapLayer *mapLayer )
172182
: actionType( MapLayerAction )

‎src/gui/qgsactionmenu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class GUI_EXPORT QgsActionMenu : public QMenu
119119
private slots:
120120
void triggerAction();
121121
void reloadActions();
122+
void layerWillBeDeleted();
122123

123124
private:
124125
void init();

0 commit comments

Comments
 (0)
Please sign in to comment.