2

I used this line of code in PyQGIS to get to project's home path.

path=os.path.join(QgsProject.instance().homePath(), "tt.gpkg").replace("\\","/")

Now I thought this is the path to where the project lies. But it comes that this is the path to where first/original project was saved.

Is that so or I might be wrong here?

2
  • 1
    It is not clear what your question is. Commented Apr 15, 2022 at 22:56
  • is it giving a path to original Qgis project, from which was conecutively been saved some number of Qgis projects / Save-as ? I have tested and it seems so. Commented Apr 16, 2022 at 15:28

1 Answer 1

5

When you save the project with a different name, the project that is open now is the one in the path you just saved. QGIS closes the original project.

Let's say the project's path is C:\test1\project1.qgz. If you save as project2.qgs to C:\test2, QGIS closes C:\test1\project1.qgz and loads C:\test2\project2.qgz.

Therefore, homePath returns C:\test2 after saving as project2.qgz.

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