Bug report #13166

Loading a shapefile from a standalone script now crashes if no QApplication has been created

Added by Alessandro Pasotti over 4 years ago. Updated over 4 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Data Provider
Affected QGIS version:master Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:Yes Copied to github as #:21229

Description

The suggested skeleton for pyqgis standalone scripts was:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from qgis.core import *

QgsApplication.setPrefixPath("/usr", True)
QgsApplication.initQgis()

# Uncomment to remove crash
#import sys
#from PyQt4 import QtGui
#app = QtGui.QApplication(sys.argv)

# Crashes in QgsOgrProvider ctor
layer = QgsVectorLayer('my.shp', 'my', 'ogr')
print layer.isValid()

Now this example crashes in QgsOgrProvider constructor, unless a QApplication exists.

I'm sure this was not the case in 2.8 and previous versions.

I'm not sure that this is a bug. If it isn't, the documentation should be changed to indicate that a QApplication is always needed, even when the script is not to be run interactively or does not use any GUI classes, this would mean that there will be no more two different kind of pyQGis standalon applications: standalone scripts (no GUI, no QApplication needed) and standard PyQt QApplication style applications.

Associated revisions

Revision f528cb80
Added by Jürgen Fischer over 4 years ago

fix connection pool crash without qapplication (fixes #13166)

Revision b1388a56
Added by Jürgen Fischer over 4 years ago

fix connection pool crash without qapplication (fixes #13166)

(cherry picked from commit f528cb80df7391435aebf47ffb73e4f4081c0ab7)

History

#1 Updated by Alessandro Pasotti over 4 years ago

  • Crashes QGIS or corrupts data changed from No to Yes

Some more informations when debugging on master:

#0  QObject::thread (this=0x0) at kernel/qobject.cpp:1370
#1  0x00007fffd5c58f8b in QgsConnectionPoolGroup<QgsOgrConn*>::initTimer(QObject*) () from /home/ale/apps/lib/qgis/plugins/libogrprovider.so
#2  0x00007fffd5c58135 in QgsOgrConnPoolGroup::QgsOgrConnPoolGroup(QString) () from /home/ale/apps/lib/qgis/plugins/libogrprovider.so
#3  0x00007fffd5c58252 in QgsOgrConnPool::ref(QString const&) () from /home/ale/apps/lib/qgis/plugins/libogrprovider.so
#4  0x00007fffd5c583b4 in QgsOgrConnPool::refS(QString const&) () from /home/ale/apps/lib/qgis/plugins/libogrprovider.so
#5  0x00007fffd5c47cb4 in QgsOgrProvider::QgsOgrProvider(QString const&) () from /home/ale/apps/lib/qgis/plugins/libogrprovider.so
#6  0x00007fffd5c5322b in classFactory () from /home/ale/apps/lib/qgis/plugins/libogrprovider.so
#7  0x00007ffff4f69bf9 in QgsProviderRegistry::provider(QString const&, QString const&) () from /usr/lib/libqgis_core.so.2.10.1
#8  0x00007ffff4fb5896 in QgsVectorLayer::setDataProvider(QString const&) () from /usr/lib/libqgis_core.so.2.10.1
#9  0x00007ffff4fb612e in QgsVectorLayer::setDataSource(QString, QString, QString, bool) () from /usr/lib/libqgis_core.so.2.10.1
#10 0x00007ffff4fb73cf in QgsVectorLayer::QgsVectorLayer(QString, QString, QString, bool) () from /usr/lib/libqgis_core.so.2.10.1
#11 0x00007ffff602ba85 in sipQgsVectorLayer::sipQgsVectorLayer(QString, QString, QString, bool) () from /usr/lib/python2.7/dist-packages/qgis/_core.so

#2 Updated by Jürgen Fischer over 4 years ago

  • Status changed from Open to Closed

Also available in: Atom PDF