Skip to content

Commit 4272f5d

Browse files
committedNov 20, 2017
[bugfix] Do not crash when testing empty virtual layers
Fixes #17489 Require backporting
1 parent e9ce901 commit 4272f5d

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed
 

‎src/providers/virtual/qgsvirtuallayersourceselect.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,20 @@ QgsVirtualLayerDefinition QgsVirtualLayerSourceSelect::getVirtualLayerDef()
199199
void QgsVirtualLayerSourceSelect::onTestQuery()
200200
{
201201
QgsVirtualLayerDefinition def = getVirtualLayerDef();
202-
203-
std::unique_ptr<QgsVectorLayer> vl( new QgsVectorLayer( def.toString(), QStringLiteral( "test" ), QStringLiteral( "virtual" ) ) );
204-
if ( vl->isValid() )
205-
{
206-
QMessageBox::information( nullptr, tr( "Virtual layer test" ), tr( "No error" ) );
207-
}
208-
else
202+
// If the definition is empty just do nothing.
203+
// TODO: a validation function that can enable/disable the test button
204+
// according to the validity of the active layer definition
205+
if ( ! def.toString().isEmpty() )
209206
{
210-
QMessageBox::critical( nullptr, tr( "Virtual layer test" ), vl->dataProvider()->error().summary() );
207+
std::unique_ptr<QgsVectorLayer> vl( new QgsVectorLayer( def.toString(), QStringLiteral( "test" ), QStringLiteral( "virtual" ) ) );
208+
if ( vl->isValid() )
209+
{
210+
QMessageBox::information( nullptr, tr( "Virtual layer test" ), tr( "No error" ) );
211+
}
212+
else
213+
{
214+
QMessageBox::critical( nullptr, tr( "Virtual layer test" ), vl->dataProvider()->error().summary() );
215+
}
211216
}
212217
}
213218

0 commit comments

Comments
 (0)
Please sign in to comment.