Skip to content

Commit cb5ef02

Browse files
committed
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.
1 parent 6e8d19c commit cb5ef02

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

src/core/raster/qgsrasterlayer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
196196
const QString & baseName = QString::null,
197197
bool loadDefaultStyleFlag = true );
198198

199+
//TODO - QGIS 3.0
200+
//This constructor is confusing if used with string literals for providerKey,
201+
//as the previous constructor will be called with the literal for providerKey
202+
//implicitly converted to a bool.
203+
//for QGIS 3.0, make either constructor explicit or alter the signatures
199204
/** \brief [ data provider interface ] Constructor in provider mode */
200205
QgsRasterLayer( const QString & uri,
201206
const QString & baseName,

src/gui/qgsrasterformatsaveoptionswidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ QString QgsRasterFormatSaveOptionsWidget::validateOptions( bool gui, bool report
310310
settings.setValue( "/Projections/defaultBehaviour", "useProject" );
311311
}
312312
tmpLayer = true;
313-
rasterLayer = new QgsRasterLayer( mRasterFileName, QFileInfo( mRasterFileName ).baseName(), "gdal" );
313+
rasterLayer = new QgsRasterLayer( mRasterFileName, QFileInfo( mRasterFileName ).baseName(), QString( "gdal" ) );
314314
// restore /Projections/defaultBehaviour
315315
if ( defaultProjectionOption == "prompt" )
316316
{

tests/src/core/testqgslegendrenderer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ void TestQgsLegendRenderer::init()
127127

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

133133
QgsCategoryList cats;

tests/src/core/testziplayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ QgsMapLayer *TestZipLayer::getLayer( QString myPath, QString myName, QString myP
110110
}
111111
else if ( myProviderKey == "gdal" )
112112
{
113-
myLayer = new QgsRasterLayer( myPath, myName, "gdal" );
113+
myLayer = new QgsRasterLayer( myPath, myName, QString( "gdal" ) );
114114
}
115115
// item should not have other provider key, but if it does will return NULL
116116

0 commit comments

Comments
 (0)