Skip to content

Commit 01b4eeb

Browse files
committedJun 2, 2017
[addlayerbutton] Prevent a crash when the layer list is rebuilt after a change in the layer tree
1 parent 14cc77c commit 01b4eeb

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed
 

‎src/providers/virtual/qgsvirtuallayersourceselect.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,14 @@ QgsVirtualLayerSourceSelect::QgsVirtualLayerSourceSelect( QWidget *parent, Qt::W
8282
connect( mLayerNameCombo, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsVirtualLayerSourceSelect::onLayerComboChanged );
8383
onLayerComboChanged( mLayerNameCombo->currentIndex() );
8484

85-
// prepare embedded layer selection dialog and
85+
// Prepare embedded layer selection dialog and
8686
// connect to model changes in the treeview
8787
if ( mTreeView )
8888
{
8989
mEmbeddedSelectionDialog = new QgsEmbeddedLayerSelectDialog( this, mTreeView );
90-
connect( mTreeView->model(), &QAbstractItemModel::rowsInserted, this, &QgsVirtualLayerSourceSelect::updateLayersList );
90+
// Queued connection here prevents the updateLayerList to run before the tree layer
91+
// pointer points to the effective layer.
92+
connect( mTreeView->model(), &QAbstractItemModel::rowsInserted, this, &QgsVirtualLayerSourceSelect::updateLayersList, Qt::QueuedConnection );
9193
connect( mTreeView->model(), &QAbstractItemModel::rowsRemoved, this, &QgsVirtualLayerSourceSelect::updateLayersList );
9294
connect( mTreeView->model(), &QAbstractItemModel::dataChanged, this, &QgsVirtualLayerSourceSelect::updateLayersList );
9395
}
@@ -247,6 +249,7 @@ void QgsVirtualLayerSourceSelect::updateLayersList()
247249
QgsLayerTreeModel *model = qobject_cast<QgsLayerTreeModel *>( mTreeView->model() );
248250
Q_FOREACH ( QgsLayerTreeLayer *layer, model->rootGroup()->findLayers() )
249251
{
252+
Q_ASSERT( layer->layer() );
250253
if ( layer->layer()->type() == QgsMapLayer::VectorLayer && static_cast<QgsVectorLayer *>( layer->layer() )->providerType() == QLatin1String( "virtual" ) )
251254
{
252255
// store layer's id as user data

0 commit comments

Comments
 (0)
Please sign in to comment.