I am trying to utilize the C++ code examples from blog.qgis.org, specifically Tutorial 4, Adding Rasters to QGIS Map Canvas.
I am successfully able to run the example loading a GeoTIFF with QGIS 1.4, however with 1.8 I get "Layer is Not Valid". As a note, the same GeoTIFF file was able to be loaded in the QGIS 1.8 application just fine, but not in the example code. I've tried with several different files, with the same result. Is there additions to the 1.8 API which require additional calls to get this functionality to work? Problem code below. The full example code can be found at http://blog.qgis.org/node/94
Operating System: Fedora 17 64-bit, QGIS 1.8.0
void MainWindow::addLayer()
{
QString myFileName = QFileDialog::getOpenFileName(this, tr("Open File"),
QCoreApplication::applicationDirPath () + "/data",
tr("GeoTiff (*.tif)"));
QFileInfo myRasterFileInfo(myFileName);
QgsRasterLayer * mypLayer = new QgsRasterLayer(myRasterFileInfo.filePath(),
myRasterFileInfo.completeBaseName());
if (mypLayer->isValid())
{
qDebug("Layer is valid");
}
else
{
qDebug("Layer is NOT valid");
return;
}
