Skip to content
Browse files
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.
  • Loading branch information
wonder-sk committed Jun 21, 2018
1 parent 692f439 commit 8609a2fa88dfb7e85919689ccc96abcf97c3aaac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
@@ -47,6 +47,7 @@ void QgsActionMenu::init()
connect( mLayer, &QgsVectorLayer::editingStarted, this, &QgsActionMenu::reloadActions );
connect( mLayer, &QgsVectorLayer::editingStopped, this, &QgsActionMenu::reloadActions );
connect( mLayer, &QgsVectorLayer::readOnlyChanged, this, &QgsActionMenu::reloadActions );
connect( mLayer, &QgsMapLayer::willBeDeleted, this, &QgsActionMenu::layerWillBeDeleted );

@@ -167,6 +168,15 @@ void QgsActionMenu::reloadActions()
emit reinit();

void QgsActionMenu::layerWillBeDeleted()
// here we are just making sure that we are not going to have reloadActions() called again
// with a dangling pointer to a layer when actions get removed on QGIS exit
mLayer = nullptr;
disconnect( QgsGui::mapLayerActionRegistry(), &QgsMapLayerActionRegistry::changed, this, &QgsActionMenu::reloadActions );

QgsActionMenu::ActionData::ActionData( QgsMapLayerAction *action, QgsFeatureId featureId, QgsMapLayer *mapLayer )
: actionType( MapLayerAction )
@@ -119,6 +119,7 @@ class GUI_EXPORT QgsActionMenu : public QMenu
private slots:
void triggerAction();
void reloadActions();
void layerWillBeDeleted();

void init();

0 comments on commit 8609a2f

Please sign in to comment.