Skip to content

Commit ac109e4

Browse files
committed
[bugfix] Do not crash when testing empty virtual layers
Fixes #17489 Backported from master
1 parent 33e939c commit ac109e4

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/providers/virtual/qgsvirtuallayersourceselect.cpp

+13-8
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,20 @@ QgsVirtualLayerDefinition QgsVirtualLayerSourceSelect::getVirtualLayerDef()
229229
void QgsVirtualLayerSourceSelect::onTestQuery()
230230
{
231231
QgsVirtualLayerDefinition def = getVirtualLayerDef();
232-
233-
QScopedPointer<QgsVectorLayer> vl( new QgsVectorLayer( def.toString(), "test", "virtual" ) );
234-
if ( vl->isValid() )
235-
{
236-
QMessageBox::information( nullptr, tr( "Virtual layer test" ), tr( "No error" ) );
237-
}
238-
else
232+
// If the definition is empty just do nothing.
233+
// TODO: a validation function that can enable/disable the test button
234+
// according to the validity of the active layer definition
235+
if ( ! def.toString().isEmpty() )
239236
{
240-
QMessageBox::critical( nullptr, tr( "Virtual layer test" ), vl->dataProvider()->error().summary() );
237+
QScopedPointer<QgsVectorLayer> vl( new QgsVectorLayer( def.toString(), "test", "virtual" ) );
238+
if ( vl->isValid() )
239+
{
240+
QMessageBox::information( nullptr, tr( "Virtual layer test" ), tr( "No error" ) );
241+
}
242+
else
243+
{
244+
QMessageBox::critical( nullptr, tr( "Virtual layer test" ), vl->dataProvider()->error().summary() );
245+
}
241246
}
242247
}
243248

0 commit comments

Comments
 (0)