I'm having trouble with QGIS (2.18.12) project files on Windows, if saved via Python command. The project file is saved via:

project = QgsProject.instance()

The file is saved, I can open it and it contains all the layers it should.

However if I first use the save command (described above) and then press the QGIS 'Save button' (the disk symbol) I get an message saying:

Project file was changed ... (see image)

enter image description here

This confuses me as I'm in fact overwriting the existing project file. If I reopen the file it will show me the newly saved status.

Besides this the actual message doesn't seem to change anything. Whether I press 'OK' or 'Cancel' the actual file content of the project file, doesn't change or revert (if I press 'Cancel' and close). When reloaded the qgs-file always shows the correct status (= the project stats when the Python save-command was executed).

The date/time in the message seems to refer to the date I originally saved the project file via the QGIS 'Save Button'.

If I press the save button again the message won't appear again (until I use the python save-command). Also, if I save the project via python, then close the project, reload it and press the QGIS 'Save Button' the message won't appear.

How can I save a QGIS project file and use the QGIS 'save button' afterwards without this message showing up?

  • 2
    Funny, I'm guessing a signal isn't sent using your method to QGIS telling it the current project is saved. An alternative could be to trigger the Project Save button instead of using QgsProject.instance(). Something like: from PyQt4.QtGui import QAction; iface.mainWindow().findChild( QAction, 'mActionSaveProject' ).trigger()
    – Joseph
    Commented Sep 28, 2017 at 9:18
  • 1
    Hey thanks for the hint, this works. Only downside is that I can only use this for 'save' not 'save as...', because 'save as...' requires user input. Meaning that it doesn't work if I want to create a new specific qgs project file and write it without the 'save as...' user dialog (eg: file = QFileInfo(output_path) project.write(file)
    – swad
    Commented Sep 28, 2017 at 15:13
  • I'm using QGIS version 3.16.16 and still have the same issue.
    – Motti
    Commented Feb 10, 2022 at 8:49

1 Answer 1


I know this post is old, but for anyone still searching for a potential solution, I have created a plugin that is now on the official QGIS plugin repository: https://plugins.qgis.org/plugins/SaveAllScript/

It should fix this problem and also adds some additional functionality for vector and raster layers

  • 1
    This is not answering the question. The Q is about programming. Commented Jun 30, 2023 at 8:08
  • I would like to clarify that this comment is relevant to the question because I created a QGIS plug-in that addresses some of the questions that the original poster had. I am sharing it here because maybe people in the future who also share the same questions can easily fix their problem with the plug-in. People are welcome to reference the code for the plug-in in order to help them with their own programming goals. Commented Jun 30, 2023 at 23:18
  • 1
    No, sorry but that is not how this site works. Pointing people to look at your plugin's code is on the same level as saying "here is the QGIS docs, just read them". A good answers has a solution tailored to the exact question and is self-contained, without any need for additional external steps. Also, the question was about Python code and a specific dialog's behaviour. Commented Aug 8, 2023 at 12:09

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.