<div dir="ltr">Hi Matthias,<div><br></div><div>Yes it seems to work !</div>I guess I didn't find it because I was looking for load/open rather an add...<div><br><div>I don't get the save prompt if the current project what modified though, but in my case it's good enough.</div><div><br></div><div>Thanks a lot for the quick answer !</div><div><br></div><div>Olivier<br><div><div><br></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-03-17 10:19 GMT+01:00 Matthias Kuhn <span dir="ltr"><<a href="mailto:matthias@opengis.ch" target="_blank">matthias@opengis.ch</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
Hi,<br>
<br>
Does <br>
<br>
iface.addProject( path ) work?<span class="HOEnZb"><font color="#888888"><br>
<br>
Matthias</font></span><div><div class="h5"><br>
<br>
<div>On 03/17/2015 10:16 AM, Olivier Dalang
wrote:<br>
</div>
</div></div><blockquote type="cite"><div><div class="h5">
<div dir="ltr">Hi !
<div><br>
</div>
<div>I'm trying to load a project file using python in a plugin,
but am encountering some problems.</div>
<div><br>
</div>
<div>I simply want to have exactly the same behavior as if the
user was choosing "open" from the project menu, and selecting
one particular file.</div>
<div><br>
</div>
<div>The C++ QgisApp class has an void openProject(const QString
&fileName) method which I suspect to do what I want, but
if I'm not mistaken, there's no access to QgisApp through
python.</div>
<div>The python QgisInterface class has no such method. It only
has a reference to the QAction triggering the open file
dialog, but that's not helping.</div>
<div><br>
</div>
<div>So I'm using these lines :</div>
<div><br>
</div>
<div>
<div> QgsProject.instance().clear()</div>
<div>
QgsProject.instance().setFileName('C:\mypath\myfile.qgs')</div>
<div> QgsProject.instance().read()</div>
</div>
<div><br>
</div>
<div>It seems to work more or less.</div>
<div><br>
</div>
<div>But the behavior is not exactly the same : </div>
<div><br>
</div>
<div>- postgres layers for which I have a stored user/password
in the browser (not in the project file) are simply ignored
(there's not even an user/password prompt, nor the handle bad
layers dialog).</div>
<div>- there's no save prompt if the current project was
modified<br>
</div>
<div>- I seem to have some crashes every now and then</div>
<div><br>
</div>
<div>Is there a way to simply open a file using python given
it's path ? Am I just missing it ?</div>
<div><br>
</div>
<div>Thanks for your help !!</div>
<div><br>
</div>
<div>Olivier</div>
</div>
<br>
<fieldset></fieldset>
<br>
</div></div><span class=""><pre>_______________________________________________
Qgis-developer mailing list
<a href="mailto:Qgis-developer@lists.osgeo.org" target="_blank">Qgis-developer@lists.osgeo.org</a>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a></pre>
</span></blockquote>
<br>
</div>
<br>_______________________________________________<br>
Qgis-developer mailing list<br>
<a href="mailto:Qgis-developer@lists.osgeo.org">Qgis-developer@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br></blockquote></div><br></div>