[QGIS-Developer] Problem reading project file

Denis Rouzaud denis.rouzaud at gmail.com
Mon May 8 05:00:03 PDT 2017


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 <hoettges at fh-aachen.de> 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/
> hoettges at fh-aachen.de
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20170508/5f534e5f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ihobgfpmjnpaefje.png
Type: image/png
Size: 839 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20170508/5f534e5f/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ihobgfpmjnpaefje.png
Type: image/png
Size: 839 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20170508/5f534e5f/attachment-0001.png>


More information about the QGIS-Developer mailing list