[Qgis-developer] PyQGIS Segmentation fault when reading from Spatialite data source

Eric Goddard egoddard1010 at gmail.com
Fri Apr 29 09:06:29 PDT 2016


Hello all,

I'm working on a sync script for use with IntraMaps Roam for offline
editing. My QGIS version is 2.14.1 (Tested on Fedora 23, Ubuntu 14.04,
and Windows 7 x64). I'm using a standalone pyqgis script that creates
the connection to the postgis data source and the spatialite
datasource that roam uses locally. At this step I've just checked that
each layer is valid, which they are, but after calling the exitQgis()
method at the end of the script I get a segmentation fault. I think it
is related to https://github.com/qgis/QGIS/pull/2944, but that
specifically says for invalid layers.

I tried removing the layer from the QgsMapLayerRegistry, but that
doesn't help. Is there another way I can try to explicitly close the
connection to avoid the segmentation fault? Technically everything
will complete before the crash, but I don't know how IntraMaps roam
will respond to the sync script crashing, and I would (obviously)
prefer my script to not crash every time it runs. The code is below.

import os
import sys
from qgis.core import *

QgsApplication.setPrefixPath("C:/OsGeo4W/apps/qgis", True)
qgs = QgsApplication(sys.argv, False)
qgis.initQgis()

sp_uri = QgsDataSourceURI()
sp_uri.setDatabase('_data/csis.sqlite')
schema = ''
table = 'facilities_envt'
geom_column = 'Geometry'
sp_uri.setDataSource(schema, table, geom_column)
sp_layer = QgsVectorLayer(sp_uri.uri(), "Disconnected Layer", "spatialite")

print sp_layer.isValid() # Prints True

qgs.exitQgis() # segfault :(

Thanks!
Eric


More information about the Qgis-developer mailing list