Skip to content
Permalink
Browse files

Avoid 'array compared against 0' error for QgsRasterLayer constructor

... by explicitly passing QString arguments. Otherwise the string
literals are implictly converted to bool and the wrong constructor
is called.

This is not an ideal solution as the API is still misleading, but I
can't see an alternative solution without breaking API and making
one of the constructors explicit or changing their signature.
  • Loading branch information
nyalldawson committed Feb 4, 2015
1 parent 6e8d19c commit cb5ef020f362284631638ffc6614768cd235a7e8
@@ -196,6 +196,11 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
const QString & baseName = QString::null,
bool loadDefaultStyleFlag = true );

//TODO - QGIS 3.0
//This constructor is confusing if used with string literals for providerKey,
//as the previous constructor will be called with the literal for providerKey
//implicitly converted to a bool.
//for QGIS 3.0, make either constructor explicit or alter the signatures
/** \brief [ data provider interface ] Constructor in provider mode */
QgsRasterLayer( const QString & uri,
const QString & baseName,
@@ -310,7 +310,7 @@ QString QgsRasterFormatSaveOptionsWidget::validateOptions( bool gui, bool report
settings.setValue( "/Projections/defaultBehaviour", "useProject" );
}
tmpLayer = true;
rasterLayer = new QgsRasterLayer( mRasterFileName, QFileInfo( mRasterFileName ).baseName(), "gdal" );
rasterLayer = new QgsRasterLayer( mRasterFileName, QFileInfo( mRasterFileName ).baseName(), QString( "gdal" ) );
// restore /Projections/defaultBehaviour
if ( defaultProjectionOption == "prompt" )
{
@@ -127,7 +127,7 @@ void TestQgsLegendRenderer::init()

static char raster_array[] = { 1, 2, 2, 1 };
QString rasterUri = QString( "MEM:::DATAPOINTER=%1,PIXELS=2,LINES=2" ).arg(( qulonglong ) raster_array );
mRL = new QgsRasterLayer( rasterUri, "Raster Layer", "gdal" );
mRL = new QgsRasterLayer( rasterUri, QString( "Raster Layer" ), QString( "gdal" ) );
QgsMapLayerRegistry::instance()->addMapLayer( mRL );

QgsCategoryList cats;
@@ -110,7 +110,7 @@ QgsMapLayer *TestZipLayer::getLayer( QString myPath, QString myName, QString myP
}
else if ( myProviderKey == "gdal" )
{
myLayer = new QgsRasterLayer( myPath, myName, "gdal" );
myLayer = new QgsRasterLayer( myPath, myName, QString( "gdal" ) );
}
// item should not have other provider key, but if it does will return NULL

0 comments on commit cb5ef02

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