Bug report #21350
QGIS Crash when running Python script
Status: | Closed | ||
---|---|---|---|
Priority: | Normal | ||
Assignee: | - | ||
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 |
Description
User Feedback¶
I ran the following Python script and QGIS crashed:
from qgis.core import *
import processing
- supply path to qgis install location
QgsApplication.setPrefixPath("C:/Program Files/QGIS 3.4", True)
- create a reference to the QgsApplication
- setting the second argument to True enables the GUI, which we need
- to do since this is a custom application
qgs = QgsApplication([], True)
- load providers
qgs.initQgis()
- Write your code here to load some layers, use processing
- algorithms, etc.
- load layers
iface.addVectorLayer("J:/GIS/Projects/TCARTA/00_CandidatePack/London_Major_roads_6m_buffer_32631.shp","Roads","ogr")
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")
- When your script is complete, call exitQgis() to remove the
- provider and layer registries from memory
qgs.exitQgis()
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 Info
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
History
#1 Updated by Nyall Dawson almost 6 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.