Bug report #775

CreateVectorLayer(), setDataProvider("ogr") segfault

Added by crschmidt - about 13 years ago. Updated about 13 years ago.

Status:Closed
Priority:Low
Assignee:Martin Dobias
Category:Data Provider
Affected QGIS version: Regression?:No
Operating System:OS X Easy fix?:No
Pull Request or Patch supplied: Resolution:fixed
Crashes QGIS or corrupts data: Copied to github as #:10834

Description

The following commands in the Python console will crash qgis:

import qgis.core as c
l = c.QgsVectorLayer()
l.setDataProvider("ogr")

Backtrace:

Thread 0 Crashed:
0   libstdc++.6.dylib       0x90b2f9de std::basic_string<char, std::char_traits<char>, std::allocator<char> >::assign(char const*) + 20
1   org.gdal.gdal           0x0250d7e9 OGRILI1DataSource::Open(char const*, int) + 105
2   org.gdal.gdal           0x0250dc94 OGRILI1Driver::Open(char const*, int) + 60
3   org.gdal.gdal           0x0248f325 OGRSFDriverRegistrar::Open(char const*, int, OGRSFDriver**) + 85
4   libogrprovider.so       0x1c2920de [[QgsOgrProvider]]::QgsOgrProvider[in-charge](QString const&) + 1742
5   libogrprovider.so       0x1c292495 classFactory + 37
6   libqgis_core.dylib      0x01d45284 [[QgsProviderRegistry]]::getProvider(QString const&, QString const&) + 230
7   libqgis_core.dylib      0x01d607ab [[QgsVectorLayer]]::setDataProvider(QString const&) + 89
8   core.so                 0x1db235f8 meth_QgsVectorLayer_setDataProvider + 156

The problem is presumably the null qstring provided as the second arg to getProvider, which should be a filename, but isn't.

History

#1 Updated by Martin Dobias about 13 years ago

Hi,

I can replicate the problem and I'll fix it later, however this is not the way how the layers should be instantiated. In fact setDataProvider() should be protected function. You can find here how to open layers:

http://wiki.qgis.org/qgiswiki/PythonBindings

Martin

#2 Updated by Martin Dobias about 13 years ago

  • Resolution set to fixed
  • Status changed from Open to Closed

Fixed in .

setDataProvider() is now private.

I guess your intent was to create a new layer here. It's stupid but there's no straightforward way to do it in QGIS. But it's possible to create an empty shapefile with QgsVectorFileWriter and then use it to construct a QgsVectorLayer...

Also available in: Atom PDF