[Qgis-developer] Saving a project using QGIS (Python) API loses mapcanvas and other XML nodes

Alberti, K. (Koko) K.Alberti at uu.nl
Mon Dec 1 05:10:09 PST 2014

Hi qgis-dev,

Apologies for the crosspost (on GIS stackexchange [1]), but I'm hoping this is a more appropriate audience for my question. I'm trying to open, manipulate, and save a QGIS project file using a standalone python script. However, upon saving the project, the output file is missing the <mapcanvas> and <legend> XML nodes. Does anyone know why this happens and if it is the expected behaviour or that something else is going on? When these nodes are missing and the project is then served via QGIS server the GetProjectSettings request breaks.

Looking through the source code of QgsProject::write() at http://qgis.org/api/qgsproject_8cpp_source.html#l01090 it says "let map canvas and legend write their information", so it seems like something goes wrong at this point. Is the map canvas not available in a standalone python script or is nothing being done with the signal? I'm afraid I don't know enough of the details to be able to debug this any deeper, hence my question here. The script I'm using is at http://pastebin.com/Cphcywkx and on SE [1]. If it is indeed a bug I can file an issue in the tracker.


[1] http://gis.stackexchange.com/questions/122849/saving-a-qgis-project-using-the-api-loses-mapcanvas-and-other-xml-nodes

More information about the Qgis-developer mailing list