1

I have data for a PostgreSQL connection. After writing the data in QgsSettings. The connection works but in the Data Source Manager under PostgreSQL connections is nothing documented. After I restart QGIS, the Data Source Manager shows me my connection.

qs = QgsSettings()
qs.beginGroup('/PostgreSQL/connections')
geo_data = "/"+ database_name

qs.setValue(geo_data +"/sslmode","SslDisable")
qs.setValue(geo_data +'/savePassword',"true")
qs.setValue(geo_data +'/saveUsername',"true")
qs.setValue(geo_data + '/username',"user")
qs.setValue(geo_data + '/password',"Password")
qs.setValue(geo_data + '/host',"Data Source")
qs.setValue(geo_data + '/database',"database")
qs.setValue(geo_data + '/port',"5432")

qs.sync()

I thought that the settings getting saved automatically and for safety, I also used the sync() function. Maybe someone has an idea of what is wrong.

1 Answer 1

2

You probably need to reload your connections instead of qs.sync():

iface.reloadConnections()

Based on this How to open and add SQLite connection to browser with PyQgis

1
  • it works for MSSQL and PostgreSQL but not for Oracle Commented Feb 24, 2020 at 11:08

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.