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 <[email protected]> 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/ > [email protected] > _______________________________________________ > QGIS-Developer mailing list > [email protected] > List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer > Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
_______________________________________________ QGIS-Developer mailing list [email protected] List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
