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?

  • 1
    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 Sep 28 '17 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 Sep 28 '17 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.