Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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 4272f5d
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/providers/virtual/qgsvirtuallayersourceselect.cpp
Expand Up @@ -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() );
}
}
}

Expand Down

0 comments on commit 4272f5d

Please sign in to comment.