[QGIS-Developer] createvectorTable error: Could not retrieve driver for connection

Raymond Nijssen r.nijssen at terglobo.nl
Wed Nov 30 09:08:26 PST 2022


Hi developers,

Recently some users of my plugin started getting errors in the code that 
creates a .gpkg file with a table. I wrote a piece of test code:

gpkg_fn = '/home/raymond/tmp/test.gpkg'
md = QgsProviderRegistry.instance().providerMetadata('ogr')
conn = md.createConnection(gpkg_fn, {})
fields = QgsFields()
fields.append(QgsField('key', QVariant.String))
fields.append(QgsField('value', QVariant.String))
conn.createVectorTable('', 'test', fields, QgsWkbTypes.NoGeometry, 
QgsCoordinateReferenceSystem(), True, {})


That last line *sometimes* results in this error:

_core.QgsProviderConnectionException: Could not retrieve driver for 
connection



I cannot reproduce the error on my laptop (Linux), but Richard tried a 
few QGIS versions in both Windows and Linux and *sometimes* got the 
error and sometimes not. Even in the same application, the error 
disappeared after running another version of QGIS simultaneously... :/

No clue if this error is GDAL or Qt or whatever related, pretty puzzling 
for me. Hope anyone can help!

Kind regards,
Raymond


More information about the QGIS-Developer mailing list