<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><DIV>Hi,</DIV>
<DIV> </DIV>
<DIV>i am new to the qgis api using the code examples to get a better understanding.</DIV>
<DIV> </DIV>
<DIV><A href="https://github.com/qgis/qgis-code-examples">https://github.com/qgis/qgis-code-examples</A> </DIV>
<DIV> </DIV>
<DIV>unfortunately I get a "layer not valid" message for examples 1 and 2.</DIV>
<DIV> </DIV>
<DIV>fortunately the TIFF in example 4 does get loaded.</DIV>
<DIV> </DIV>
<DIV>so based on ex 4 i added the following lines to example 2:</DIV>
<DIV> </DIV>
<DIV id=LC105 class=line> <EM><SPAN class=n>QString</SPAN> <SPAN class=n>myFileName</SPAN> <SPAN class=o>=</SPAN> <SPAN class=n>QFileDialog</SPAN><SPAN class=o>::</SPAN><SPAN class=n>getOpenFileName</SPAN><SPAN class=p>(</SPAN><SPAN class=k>this</SPAN><SPAN class=p>,</SPAN> <SPAN class=n>tr</SPAN><SPAN class=p>(</SPAN><SPAN class=s>"Open File"</SPAN><SPAN class=p>),</SPAN></EM></DIV>
<DIV id=LC106 class=line><EM> <SPAN class=n>QCoreApplication</SPAN><SPAN class=o>::</SPAN><SPAN class=n>applicationDirPath</SPAN> <SPAN class=p>()</SPAN> <SPAN class=s>"</SPAN><SPAN class=p>,</SPAN></EM></DIV>
<DIV id=LC107 class=line><EM> <SPAN class=n>tr</SPAN><SPAN class=p>(</SPAN><SPAN class=s>"Shape (*.shp)"</SPAN><SPAN class=p>));</SPAN></EM></DIV>
<DIV id=LC108 class=line><EM> <SPAN class=n>QFileInfo</SPAN> <SPAN class=n>myVectorFileInfo</SPAN><SPAN class=p>(</SPAN><SPAN class=n>myFileName</SPAN><SPAN class=p>);</SPAN></EM></DIV>
<DIV id=LC109 class=line><EM> <SPAN class=n>QgsVectorLayer</SPAN> <SPAN class=o>*</SPAN> <SPAN class=n>mypLayer</SPAN> <SPAN class=o>=</SPAN> <SPAN class=k>new</SPAN> <SPAN class=n>QgsVectorLayer</SPAN><SPAN class=p>(</SPAN><SPAN class=n>myVectorFileInfo</SPAN><SPAN class=p>.</SPAN><SPAN class=n>filePath</SPAN><SPAN class=p>(),</SPAN> </EM></DIV>
<DIV id=LC110 class=line><EM> <SPAN class=n>myVectorFileInfo</SPAN><SPAN class=p>.</SPAN><SPAN class=n>completeBaseName</SPAN><SPAN class=p>());</SPAN></EM></DIV>
<DIV class=line><EM><SPAN class=p></SPAN></EM> </DIV>
<DIV class=line><SPAN class=p>Selecting a shapefile goes well, however I still get the "layer not valid" message </SPAN></DIV>
<DIV class=line><SPAN class=p></SPAN> </DIV>
<DIV class=line><SPAN class=p></SPAN> </DIV>
<DIV class=line><SPAN class=p></SPAN> </DIV>
<DIV class=line><SPAN class=p>In phyton loading a layer is also a problem using the code in the phyton console of Qgis:<BR><BR>----<BR>layer = QgsVectorLayer("/home/jellema/Documents/A.shp", "layer_name", "ogr")<BR>if not layer.isValid():<BR>print "Layer failed to load!" <BR>---<BR><BR><BR>However it works fine using:<BR><BR>----<BR>qgis.utils.iface.addVectorLayer("/home/jellema/Documents/A.shp", "layer_name", "ogr")<BR>----<BR></SPAN></DIV>
<DIV class=line><SPAN class=p></SPAN> </DIV>
<DIV class=line><SPAN class=p>Can somebody give me some isight on what goes wrong?</SPAN></DIV>
<DIV class=line><SPAN class=p></SPAN> </DIV>
<DIV class=line><SPAN class=p>Andre </SPAN></DIV></td></tr></table>