Bug report #21350

QGIS Crash when running Python script

Added by Peter Spurgeon almost 4 years ago. Updated almost 4 years ago.

Category:PyQGIS Console
Affected QGIS version:3.4.4 Regression?:No
Operating System:Windows 7 Easy fix?:No
Pull Request or Patch supplied:No Resolution:invalid
Crashes QGIS or corrupts data:Yes Copied to github as #:29168


User Feedback

I ran the following Python script and QGIS crashed:

from qgis.core import *
import processing

  1. supply path to qgis install location
    QgsApplication.setPrefixPath("C:/Program Files/QGIS 3.4", True)
  1. create a reference to the QgsApplication
  2. setting the second argument to True enables the GUI, which we need
  3. to do since this is a custom application

qgs = QgsApplication([], True)

  1. load providers
  1. Write your code here to load some layers, use processing
  2. algorithms, etc.
  1. load layers
    iface.addVectorLayer("J:/GIS/Projects/TCARTA/00_CandidatePack/input/London_Moving_Vehicles_Image1_32631.shp", "Moving_Vehicles_Image1", "ogr")
    iface.addVectorLayer("J:/GIS/Projects/TCARTA/00_CandidatePack/input/London_Moving_Vehicles_Image2_32631.shp", "Moving_Vehicles_Image2", "ogr")
    iface.addVectorLayer("J:/GIS/Projects/TCARTA/00_CandidatePack/input/London_Static_Vehicles_Image1_32631.shp", "Static_Vehicles_Image1", "ogr")
    iface.addVectorLayer("J:/GIS/Projects/TCARTA/00_CandidatePack/input/London_Static_Vehicles_Image2_32631.shp", "Static_Vehicles_Image2", "ogr")
  1. When your script is complete, call exitQgis() to remove the
  2. provider and layer registries from memory

Report Details

Crash ID: 9f2badebfea27d2acdf2434061d39cb3d8ecb4a9

Stack Trace

QList<QItemSelectionRange>::size :
QgsLayerTree::QgsLayerTree :
QgsLayerTree::customLayerOrder :
QgsLayerTreeMapCanvasBridge::setCanvasLayers :
QObject::event :
QApplicationPrivate::notify_helper :
QApplication::notify :
QgsApplication::notify :
PyInit__core :
QCoreApplication::notifyInternal2 :
QCoreApplicationPrivate::sendPostedEvents :
qt_plugin_query_metadata :
QEventDispatcherWin32::processEvents :
TranslateMessageEx :
TranslateMessage :
QEventDispatcherWin32::processEvents :
qt_plugin_query_metadata :
QEventLoop::exec :
QCoreApplication::exec :
main :
BaseThreadInitThunk :
RtlUserThreadStart :

QGIS Version: 3.4.4-Madeira
QGIS code revision: f6ddc62fdb
Compiled against Qt: 5.11.2
Running against Qt: 5.11.2
Compiled against GDAL: 2.4.0
Running against GDAL: 2.4.0

System Info
CPU Type: x86_64
Kernel Type: winnt
Kernel Version: 6.1.7601


#1 Updated by Nyall Dawson almost 4 years ago

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

It's not possible to use "iface" from a standalone script, since there's no interface existing. You need to avoid using that API in your script.

Followup questions are better suited to gis.stackexchange.com, as this isn't a bug.

Also available in: Atom PDF