[GIS] QGIS / pyqgis error: wrapped C/C++ object of type QProgressBar has been deleted See log for more details

pyqgispython-2.7qgisqgis-processing

I have this error when I run some of my python scripts. It does not always occur. It always happens at the END of the script, (all script actions finish!!)

I mainly need to fix it because it is annoying and it prevents me from stringing separate scripts together.

The traceback I get is:

Traceback (most recent call last):
          File "C:/QGIS/apps/qgis/./python/plugins\processing\core\GeoAlgorithm.py", line 203, in execute
            self.processAlgorithm(progress)
          File "C:/QGIS/apps/qgis/./python/plugins\processing\script\ScriptAlgorithm.py", line 378, in processAlgorithm
            exec((script), ns)
          File "<string>", line 146, in <module>
        RuntimeError: wrapped C/C++ object of type QProgressBar has been deleted

However the line it refers to does not seem to make any sense:

error2 = QgsVectorFileWriter.writeAsVectorFormat(bufflayer, buffdef, "CP1250", None, "ESRI Shapefile")

Note that this and all of the python after this command always run just fine.
Any thoughts?

Best Answer

Try adding the keyword progress=None to your call, i.e. error2 = QgsVectorFileWriter.writeAsVectorFormat(bufflayer, buffdef, "CP1250", None, "ESRI Shapefile", progress=None) I have not tested this in your case, but it worked for me when calling processing algorithms from script (processing.runalg()).

Edit/summary:

Apparently, the main culprit for wonky script behavior is the progress bar that comes with processing algorithms. Your best bet is to add the keyword progress=None to every processing.runalg() call you make. As an extra measure, check the source code of any algorithms you use in your script for calls they might make to other algorithms and add progress=None to those as well.

Related Question