@@ -82,12 +82,14 @@ QgsVirtualLayerSourceSelect::QgsVirtualLayerSourceSelect( QWidget *parent, Qt::W
82
82
connect ( mLayerNameCombo , static_cast <void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this , &QgsVirtualLayerSourceSelect::onLayerComboChanged );
83
83
onLayerComboChanged ( mLayerNameCombo ->currentIndex () );
84
84
85
- // prepare embedded layer selection dialog and
85
+ // Prepare embedded layer selection dialog and
86
86
// connect to model changes in the treeview
87
87
if ( mTreeView )
88
88
{
89
89
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 );
91
93
connect ( mTreeView ->model (), &QAbstractItemModel::rowsRemoved, this , &QgsVirtualLayerSourceSelect::updateLayersList );
92
94
connect ( mTreeView ->model (), &QAbstractItemModel::dataChanged, this , &QgsVirtualLayerSourceSelect::updateLayersList );
93
95
}
@@ -247,6 +249,7 @@ void QgsVirtualLayerSourceSelect::updateLayersList()
247
249
QgsLayerTreeModel *model = qobject_cast<QgsLayerTreeModel *>( mTreeView ->model () );
248
250
Q_FOREACH ( QgsLayerTreeLayer *layer, model->rootGroup ()->findLayers () )
249
251
{
252
+ Q_ASSERT ( layer->layer () );
250
253
if ( layer->layer ()->type () == QgsMapLayer::VectorLayer && static_cast <QgsVectorLayer *>( layer->layer () )->providerType () == QLatin1String ( " virtual" ) )
251
254
{
252
255
// store layer's id as user data
0 commit comments