Unfortunately I am not able to give you an answer to the original question. I cannot think of an idea to work the way you proposed.
I think however that it is possible to solve your problem with a different approach, in particular pg_service.
In the .qgs file you can connect to the database by means of the service
parameter. instead of specifying host
, port
and user
individually.
In the .qgs file it should say service='pg_qbase'
but you can define that from the postgres connection UI in QGIS with the field named service.
While the pg_service.conf file should contain the following
[pg_qbase]
host=10.1.1.1
port=5432
user={this part is unique per machine/user}
dbname=QBASE
password=supersecretpassword!
If you want to put the password into a separate file, there is also a .pgpass file which avoids having to ship passwords in pg_service.conf or the .qgs file.
With this approach you are able to
- define database access rights per user
- while sharing one .qgs project file
- and referencing the same database from multiple .qgs files