[Qgis-developer] help, some trouble with the code example .

Martin Dobias wonder.sk at gmail.com
Wed Apr 22 10:20:01 EDT 2009


On Wed, Apr 22, 2009 at 5:29 AM, hermangz <hermangz at gmail.com> wrote:
>
> [...]
>
> When i run it. it always goes to "Layer is NOT valid" . But my shp file
> exists in the same directory.
>
> I assign myLayerPath  with full path like "c:\\qgisexample\\xxx.shp"  , and
> the result goes the same.
>
> What would the problem be ?  Any help will be appreciated , thank you.

Maybe you've forgotten to initialize QGIS libraries:
QgsApplication::setPrefixPath( "path_to_qgis", true );
QgsApplication::initQgis();

if you don't initialize the libs or specify incorrect path, you won't
be able to load vector layers.

Btw. I think that with Qt even on windows one should use forward
slashes ( / ) instead of backslashes ( \ ) when writing paths.

Regards
Martin


More information about the Qgis-developer mailing list