So after writing in a projectfile as in the cookbook in QGIS 2.14 with.

finfo = QFileInfo(filename)

I want to open that project in the main window. So I try:


But the project doesn't open. How can I open the .qgs file I've created in the window?

  • 1
    Did you close the project before trying to open it? Did you receive errors when running the code?
    – Joseph
    Commented May 30, 2017 at 14:31
  • I tried with another project open. And with no project open @joseph Commented May 30, 2017 at 14:44

1 Answer 1


It is strange but if you write a project and read directly after the project does not load correctly. You can solve this strange using the clear() method, before you read the project file:

Simple script

from PyQt4.QtGui import *
from PyQt4.QtCore import *
from qgis.core import *
from qgis.utils import iface

project = QgsProject.instance() 



  • Is this explained anywhere in the qgis cookbook? Which is the closest thing to a pyqgis api I've been able to find. Commented Jun 1, 2017 at 6:51
  • I don't know, I found this solution, observing the method in the qgis core
    – Fran Raga
    Commented Jun 1, 2017 at 7:17
  • Unfortunatley it also clears the project I noticed later so it isn't optimal. Commented Jun 2, 2017 at 8:51
  • 1
    clears the project??of course,but you load again same project or anyone.
    – Fran Raga
    Commented Jun 2, 2017 at 10:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.