Skip to content

Commit 5cd8827

Browse files
committed
mapLayerActions as members - avoiding crash
mDuplicateFeatureAction and mDuplicateFeatureDigitizeAction are member pointers now. Means they are deleted when the object QgisApp is destructed (when going out of scope) and there is no crash anymore on closing QGIS.
1 parent 5522f10 commit 5cd8827

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/app/qgisapp.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7451,23 +7451,23 @@ void QgisApp::setupLayoutManagerConnections()
74517451

74527452
void QgisApp::setupDuplicateFeaturesAction()
74537453
{
7454-
QgsMapLayerAction *action = new QgsMapLayerAction( QString( tr( "Duplicate feature" ) ),
7455-
this, QgsMapLayerAction::AllActions,
7456-
QgsApplication::getThemeIcon( QStringLiteral( "/mActionDuplicateFeature.svg" ) ) );
7454+
mDuplicateFeatureAction.reset( new QgsMapLayerAction( QString( tr( "Duplicate feature" ) ),
7455+
this, QgsMapLayerAction::AllActions,
7456+
QgsApplication::getThemeIcon( QStringLiteral( "/mActionDuplicateFeature.svg" ) ) ) );
74577457

7458-
QgsGui::mapLayerActionRegistry()->addMapLayerAction( action );
7459-
connect( action, &QgsMapLayerAction::triggeredForFeature, this, [this]( QgsMapLayer * layer, const QgsFeature & feat )
7458+
QgsGui::mapLayerActionRegistry()->addMapLayerAction( mDuplicateFeatureAction.get() );
7459+
connect( mDuplicateFeatureAction.get(), &QgsMapLayerAction::triggeredForFeature, this, [this]( QgsMapLayer * layer, const QgsFeature & feat )
74607460
{
74617461
duplicateFeatures( layer, feat );
74627462
}
74637463
);
74647464

7465-
action = new QgsMapLayerAction( QString( tr( "Duplicate feature and digitize" ) ),
7466-
this, QgsMapLayerAction::AllActions,
7467-
QgsApplication::getThemeIcon( QStringLiteral( "/mActionDuplicateFeatureDigitized.svg" ) ) );
7465+
mDuplicateFeatureDigitizeAction.reset( new QgsMapLayerAction( QString( tr( "Duplicate feature and digitize" ) ),
7466+
this, QgsMapLayerAction::AllActions,
7467+
QgsApplication::getThemeIcon( QStringLiteral( "/mActionDuplicateFeatureDigitized.svg" ) ) ) );
74687468

7469-
QgsGui::mapLayerActionRegistry()->addMapLayerAction( action );
7470-
connect( action, &QgsMapLayerAction::triggeredForFeature, this, [this]( QgsMapLayer * layer, const QgsFeature & feat )
7469+
QgsGui::mapLayerActionRegistry()->addMapLayerAction( mDuplicateFeatureDigitizeAction.get() );
7470+
connect( mDuplicateFeatureDigitizeAction.get(), &QgsMapLayerAction::triggeredForFeature, this, [this]( QgsMapLayer * layer, const QgsFeature & feat )
74717471
{
74727472
duplicateFeatureDigitized( layer, feat );
74737473
}

src/app/qgisapp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,6 +2146,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
21462146

21472147
QHash< QgsPrintLayout *, QgsMapLayerAction * > mAtlasFeatureActions;
21482148

2149+
std::unique_ptr<QgsMapLayerAction> mDuplicateFeatureAction;
2150+
std::unique_ptr<QgsMapLayerAction> mDuplicateFeatureDigitizeAction;
2151+
21492152
int mProjOpen = 0;
21502153

21512154
bool gestureEvent( QGestureEvent *event );

0 commit comments

Comments
 (0)