<div dir="ltr">Hi Jörg,<div><br></div><div>You might want to try to add QCoreApplication.processEvents() after reading the project.</div><div>Here is an example of a script playing with reading/editing/saving a project using the API</div><div><a href="https://github.com/qwat/QGEP-customizer/blob/master/customizer.py#L89">https://github.com/qwat/QGEP-customizer/blob/master/customizer.py#L89</a><br></div><div><br></div><div>Good luck ;)</div><div><br></div><div>Denis</div></div><br><div class="gmail_quote"><div dir="ltr">Le ven. 5 mai 2017 à 15:47, Jörg Höttges <<a href="mailto:hoettges@fh-aachen.de">hoettges@fh-aachen.de</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div text="#000000" bgcolor="#FFFFFF">
    <font size="-1" face="Verdana">Hi, <br>
      <br>
      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. <br>
      <br>
      <br>
    </font><font size="-1"><tt>    ....<br>
        <br>
            qgsxml.write(projectfile)                       # writ</tt><tt>e</tt><tt>
        modified project file</tt><tt><br>
      </tt><tt><br>
      </tt><tt>    project = QgsProject.instance()</tt><tt><br>
      </tt><tt>    project.read(QFileInfo(projectfile))         # read
        the new project file</tt></font><font size="-1" face="Verdana"><br>
      <br>
    </font><font size="-1"><tt>    projectfile</tt></font><font size="-1" face="Verdana"> contains the name of the new *.qgs
      projectfile <br>
      <br>
      First attempt is successful, the second fails (groups are loaded
      but there are no layers), third attempt is successful, fourth
      fails and so on...<br>
      <br>
      Everything works fine when I use the menu "project > new"
      before starting the plugin. <br>
      <br>
      Have i done something wrong?<br>
    </font>
    <div class="m_9037196566876875641moz-signature"><font size="-1" face="Verdana"><br>
        Best wishes<br>
        <br>
        Jörg</font><br>
      <br>
      <table style="font-family:Verdana,Arial,Helvetica,sans-serif;font-size:80%">
        <tbody>
          <tr>
            <td style="vertical-align:top" width="50"><img src="cid:part1.19CF9045.0BA54234@fh-aachen.de" alt="FH
                Aachen" height="128" width="38"></td>
            <td width="500">
              <div class="m_9037196566876875641vcard">
                <div style="font-weight:bold" class="m_9037196566876875641fn m_9037196566876875641n"> <span class="m_9037196566876875641title">Prof. Dr.-Ing.</span> <span class="m_9037196566876875641given-name">Jörg</span> <span class="m_9037196566876875641family-name">Höttges</span> </div>
                <div>Fachbereich 2 - Bauingenieurwesen</div>
                Wasserwirtschaft und Bauinformatik<br>
                <div class="m_9037196566876875641org" style="margin-top:1em">FH Aachen<br>
                  University of Applied Sciences</div>
                <div class="m_9037196566876875641adr">
                  
                  <div class="m_9037196566876875641street-address">Bayernallee 9</div>
                  <div> <span class="m_9037196566876875641postal-code" style="display:inline;margin-right:0.2em">52066</span>
                    <span class="m_9037196566876875641locality" style="display:inline">Aachen</span>
                    | <span class="m_9037196566876875641country-name" style="display:inline">Germany</span> </div>
                </div>
                <div class="m_9037196566876875641tel" style="margin-top:1em"> T <span class="m_9037196566876875641value"><a href="tel:+49%20241%20600951176" value="+49241600951176" target="_blank">+49 (0)241 6009-51176</a></span> </div>
                <div class="m_9037196566876875641tel"> F <span class="m_9037196566876875641value">+49 (0)241
                    6009-51206</span> </div>
                <a class="m_9037196566876875641url" style="color:#00b5ad" href="http://www.fh-aachen.de/hoettges/" target="_blank">http://www.fh-aachen.de/hoettges/</a><br>
                <a class="m_9037196566876875641email" style="display:block;color:#00b5ad" href="mailto:hoettges@fh-aachen.de" target="_blank">hoettges@fh-aachen.de</a>
              </div>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>

_______________________________________________<br>
QGIS-Developer mailing list<br>
<a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank">QGIS-Developer@lists.osgeo.org</a><br>
List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a></blockquote></div>