Hi,
 
i am new to the qgis api using the code examples to get a better understanding.
 
https://github.com/qgis/qgis-code-examples 
 
unfortunately I get a "layer not valid" message for examples 1 and 2.
 
fortunately the TIFF in example 4 does get loaded.
 
so based on ex 4 i added the following lines to example 2:
 
  QString myFileName = QFileDialog::getOpenFileName(this, tr("Open File"),
                       QCoreApplication::applicationDirPath () ",
                       tr("Shape (*.shp)"));
  QFileInfo myVectorFileInfo(myFileName);
  QgsVectorLayer * mypLayer = new QgsVectorLayer(myVectorFileInfo.filePath(), 
      myVectorFileInfo.completeBaseName());
 
Selecting a shapefile goes well, however I still get the  "layer not valid" 
message 
 
 
 
In phyton loading a layer is also a problem using the code in the phyton 
console of Qgis:

----
layer = QgsVectorLayer("/home/jellema/Documents/A.shp", "layer_name", "ogr")
if not layer.isValid():
print "Layer failed to load!" 
---


However it works fine using:

----
qgis.utils.iface.addVectorLayer("/home/jellema/Documents/A.shp", "layer_name", 
"ogr")
----

 
Can somebody give me some isight on what goes wrong?
 
Andre 
_______________________________________________
Qgis-developer mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to