[Qgis-user] code running inside QGis, failing outside

PIERRE Sylvain sylvain.pierre at cg67.fr
Fri Oct 19 04:59:57 PDT 2012


I've just copied ans simplified small part of my code, I've already initialized QGis, and I'm using lots of PyQgis functions and almost everything is ok ;-)

-----Message d'origine-----
De : Alexander Bruy [mailto:alexander.bruy at gmail.com] 
Envoyé : vendredi 19 octobre 2012 13:56
À : PIERRE Sylvain
Cc : qgis-user at lists.osgeo.org
Objet : Re: [Qgis-user] code running inside QGis, failing outside

Hi,

looks like you didn't initialize QGIS. See PyQGIS CookBook [0]

[0] http://www.qgis.org/pyqgis-cookbook/intro.html#python-applications

2012/10/19 PIERRE Sylvain <sylvain.pierre at cg67.fr>:
> Hello list,
>
> The following code is running perfectly inside Qgis (1.7.2) from the 
> python console :
>
> from PyQt4 import QtCore, QtGui
> uri = QgsDataSourceURI()
> uri.setDatabase( "C:/APPLI_PDT/CANAL_DEV/bd_canal.sqlite")
> uri.setDataSource( "", "AOT_POINT", "GEOMETRY" ) layer = 
> QgsVectorLayer( uri.uri(), "AOT", "spatialite" ) provider = 
> layer.dataProvider() feat = QgsFeature() geometry = QgsGeometry()
> feat.setAttributeMap({1:QtCore.QVariant(5)})
> feat.setGeometry(geometry.fromPoint(QgsPoint(990650,110807)))
>  (res, outFeats) = provider.addFeatures( [ feat ] ) print str(res)
>
> But outside it’s failing (in my app build with python, PyQt and PyQgis).
>
> Res is set to false, and no row was insert.
>
> I’ve spent lots of time with Google, but didn’t found anything…

--
Alexander Bruy


More information about the Qgis-user mailing list