Re: [QGIS-Developer] Problem reading project file

2017-05-08 Thread Denis Rouzaud
Hi Jörg,

You might want to try to add QCoreApplication.processEvents() after reading
the project.
Here is an example of a script playing with reading/editing/saving a
project using the API
https://github.com/qwat/QGEP-customizer/blob/master/customizer.py#L89

Good luck ;)

Denis

Le ven. 5 mai 2017 à 15:47, Jörg Höttges  a écrit :

> Hi,
>
> in a QGIS-plugin I need to read a template project file (*.qgs), modify it
> to adapt it to the currently loaded database etc. using
> xml.etree.ElementTree, write it and read it again.
>
>
> 
>
> qgsxml.write(projectfile)   # write modified
> project file
>
> project = QgsProject.instance()
> project.read(QFileInfo(projectfile)) # read the new project
> file
>
> projectfile contains the name of the new *.qgs projectfile
>
> First attempt is successful, the second fails (groups are loaded but there
> are no layers), third attempt is successful, fourth fails and so on...
>
> Everything works fine when I use the menu "project > new" before starting
> the plugin.
>
> Have i done something wrong?
>
> Best wishes
>
> Jörg
>
> [image: FH Aachen]
> Prof. Dr.-Ing. Jörg Höttges
> Fachbereich 2 - Bauingenieurwesen
> Wasserwirtschaft und Bauinformatik
> FH Aachen
> University of Applied Sciences
> Bayernallee 9
> 52066 Aachen | Germany
> T +49 (0)241 6009-51176 <+49%20241%20600951176>
> F +49 (0)241 6009-51206
> http://www.fh-aachen.de/hoettges/
> hoett...@fh-aachen.de
> ___
> QGIS-Developer mailing list
> QGIS-Developer@lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

[QGIS-Developer] Problem reading project file

2017-05-05 Thread Jörg Höttges
Hi,

in a QGIS-plugin I need to read a template project file (*.qgs), modify it to 
adapt it to the currently loaded database
etc. using xml.etree.ElementTree, write it and read it again.




qgsxml.write(projectfile)   # writemodified project file

project = QgsProject.instance()
project.read(QFileInfo(projectfile)) # read the new project file

projectfilecontains the name of the new *.qgs projectfile

First attempt is successful, the second fails (groups are loaded but there are 
no layers), third attempt is successful,
fourth fails and so on...

Everything works fine when I use the menu "project > new" before starting the 
plugin.

Have i done something wrong?

Best wishes

Jörg

FH Aachen   
Prof. Dr.-Ing. Jörg Höttges
Fachbereich 2 - Bauingenieurwesen
Wasserwirtschaft und Bauinformatik
FH Aachen
University of Applied Sciences
Bayernallee 9
52066 Aachen | Germany
T +49 (0)241 6009-51176
F +49 (0)241 6009-51206
http://www.fh-aachen.de/hoettges/
hoett...@fh-aachen.de 

___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer