Skip to content
Permalink
Browse files

Fix potential crash after exporting vector layer

  • Loading branch information
nyalldawson committed Aug 3, 2018
1 parent 56024af commit 1fb87487e350691b7707d717837fd4b1cff250b7
Showing with 11 additions and 6 deletions.
  1. +11 −6 src/app/qgisapp.cpp
@@ -7349,11 +7349,13 @@ void QgisApp::saveAsVectorFileGeneral( QgsVectorLayer *vlayer, bool symbologyOpt
if ( !vlayer )
return;

auto onSuccess = [this, vlayer]( const QString & newFilename,
bool addToCanvas,
const QString & layerName,
const QString & encoding,
const QString & vectorFileName )
const QString layerId = vlayer->id();

auto onSuccess = [this, layerId]( const QString & newFilename,
bool addToCanvas,
const QString & layerName,
const QString & encoding,
const QString & vectorFileName )
{
if ( addToCanvas )
{
@@ -7363,7 +7365,10 @@ void QgisApp::saveAsVectorFileGeneral( QgsVectorLayer *vlayer, bool symbologyOpt
this->addVectorLayers( QStringList( uri ), encoding, QStringLiteral( "file" ) );
}

this->emit layerSavedAs( vlayer, vectorFileName );
// We need to re-retrieve the map layer here, in case it's been deleted during the lifetime of the task
if ( QgsVectorLayer *vlayer = qobject_cast< QgsVectorLayer * >( QgsProject::instance()->mapLayer( layerId ) ) )
this->emit layerSavedAs( vlayer, vectorFileName );

this->messageBar()->pushMessage( tr( "Layer Exported" ),
tr( "Successfully saved vector layer to <a href=\"%1\">%2</a>" ).arg( QUrl::fromLocalFile( newFilename ).toString(), QDir::toNativeSeparators( newFilename ) ),
Qgis::Success, messageTimeout() );

0 comments on commit 1fb8748

Please sign in to comment.
You can’t perform that action at this time.