[Qgis-developer] Qgis-developer Digest, Vol 86, Issue 41

Andre Jellema andre_jellema at yahoo.com
Wed Dec 19 02:52:19 PST 2012


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 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20121219/2a7dd6a1/attachment.html>


More information about the Qgis-developer mailing list