Skip to content
Permalink
Browse files

[bugfix] Do not crash when testing empty virtual layers

Fixes #17489

Require backporting
  • Loading branch information
elpaso committed Nov 20, 2017
1 parent e9ce901 commit 4272f5d8251cb3ee6a9fde3c3586dd1b2d6c738d
Showing with 13 additions and 8 deletions.
  1. +13 −8 src/providers/virtual/qgsvirtuallayersourceselect.cpp
@@ -199,15 +199,20 @@ QgsVirtualLayerDefinition QgsVirtualLayerSourceSelect::getVirtualLayerDef()
void QgsVirtualLayerSourceSelect::onTestQuery()
{
QgsVirtualLayerDefinition def = getVirtualLayerDef();

std::unique_ptr<QgsVectorLayer> vl( new QgsVectorLayer( def.toString(), QStringLiteral( "test" ), QStringLiteral( "virtual" ) ) );
if ( vl->isValid() )
{
QMessageBox::information( nullptr, tr( "Virtual layer test" ), tr( "No error" ) );
}
else
// If the definition is empty just do nothing.
// TODO: a validation function that can enable/disable the test button
// according to the validity of the active layer definition
if ( ! def.toString().isEmpty() )
{
QMessageBox::critical( nullptr, tr( "Virtual layer test" ), vl->dataProvider()->error().summary() );
std::unique_ptr<QgsVectorLayer> vl( new QgsVectorLayer( def.toString(), QStringLiteral( "test" ), QStringLiteral( "virtual" ) ) );
if ( vl->isValid() )
{
QMessageBox::information( nullptr, tr( "Virtual layer test" ), tr( "No error" ) );
}
else
{
QMessageBox::critical( nullptr, tr( "Virtual layer test" ), vl->dataProvider()->error().summary() );
}
}
}

0 comments on commit 4272f5d

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